From 5a13217ea9c07121e7d3cdcfb0ddd2aa52b90f12 Mon Sep 17 00:00:00 2001 From: ThibsG Date: Fri, 16 Oct 2020 17:58:26 +0200 Subject: Assert macro args extractor as a common function in higher --- clippy_lints/src/mutable_debug_assertion.rs | 66 +++++------------------------ 1 file changed, 11 insertions(+), 55 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index cc635c2a202..76417aa7ed0 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -1,7 +1,6 @@ -use crate::utils::{is_direct_expn_of, span_lint}; -use if_chain::if_chain; +use crate::utils::{higher, is_direct_expn_of, span_lint}; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability, StmtKind, UnOp}; +use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_middle::ty; @@ -39,66 +38,23 @@ impl<'tcx> LateLintPass<'tcx> for DebugAssertWithMutCall { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { for dmn in &DEBUG_MACRO_NAMES { if is_direct_expn_of(e.span, dmn).is_some() { - if let Some(span) = extract_call(cx, e) { - span_lint( - cx, - DEBUG_ASSERT_WITH_MUT_CALL, - span, - &format!("do not call a function with mutable arguments inside of `{}!`", dmn), - ); - } - } - } - } -} - -//HACK(hellow554): remove this when #4694 is implemented -fn extract_call<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option { - if_chain! { - if let ExprKind::Block(ref block, _) = e.kind; - if block.stmts.len() == 1; - if let StmtKind::Semi(ref matchexpr) = block.stmts[0].kind; - then { - // debug_assert - if_chain! { - if let ExprKind::Match(ref ifclause, _, _) = matchexpr.kind; - if let ExprKind::DropTemps(ref droptmp) = ifclause.kind; - if let ExprKind::Unary(UnOp::UnNot, ref condition) = droptmp.kind; - then { - let mut visitor = MutArgVisitor::new(cx); - visitor.visit_expr(condition); - return visitor.expr_span(); - } - } - - // debug_assert_{eq,ne} - if_chain! { - if let ExprKind::Block(ref matchblock, _) = matchexpr.kind; - if let Some(ref matchheader) = matchblock.expr; - if let ExprKind::Match(ref headerexpr, _, _) = matchheader.kind; - if let ExprKind::Tup(ref conditions) = headerexpr.kind; - if conditions.len() == 2; - then { - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref lhs) = conditions[0].kind { + if let Some(macro_args) = higher::extract_assert_macro_args(e) { + for arg in macro_args { let mut visitor = MutArgVisitor::new(cx); - visitor.visit_expr(lhs); + visitor.visit_expr(arg); if let Some(span) = visitor.expr_span() { - return Some(span); - } - } - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref rhs) = conditions[1].kind { - let mut visitor = MutArgVisitor::new(cx); - visitor.visit_expr(rhs); - if let Some(span) = visitor.expr_span() { - return Some(span); + span_lint( + cx, + DEBUG_ASSERT_WITH_MUT_CALL, + span, + &format!("do not call a function with mutable arguments inside of `{}!`", dmn), + ); } } } } } } - - None } struct MutArgVisitor<'a, 'tcx> { -- cgit 1.4.1-3-g733a5 From ada8c72f3f21013f789f774d4c0219c58264e663 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 1 Mar 2021 11:53:33 -0600 Subject: Add version = "Two" to rustfmt.toml Ignore UI tests since this change makes rustfmt less friendly with UI test comments. --- clippy_lints/src/await_holding_invalid.rs | 14 ++--- clippy_lints/src/float_literal.rs | 6 +- clippy_lints/src/infinite_iter.rs | 6 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/loops.rs | 6 +- clippy_lints/src/mutable_debug_assertion.rs | 6 +- clippy_lints/src/needless_continue.rs | 6 +- clippy_lints/src/open_options.rs | 12 ++-- clippy_utils/src/camel_case.rs | 6 +- clippy_utils/src/lib.rs | 12 ++-- clippy_utils/src/ptr.rs | 6 +- rustfmt.toml | 1 + tests/lint_message_convention.rs | 4 +- .../upper_case_acronyms.rs | 5 +- .../upper_case_acronyms.stderr | 4 +- tests/ui/auxiliary/macro_rules.rs | 6 +- tests/ui/blocks_in_if_conditions.fixed | 33 ++++------ tests/ui/blocks_in_if_conditions.rs | 33 ++++------ tests/ui/blocks_in_if_conditions.stderr | 10 +-- tests/ui/checked_unwrap/simple_conditionals.rs | 14 +++-- tests/ui/crashes/ice-6256.rs | 1 + tests/ui/crashes/ice-6256.stderr | 6 +- tests/ui/dbg_macro.rs | 6 +- tests/ui/dbg_macro.stderr | 16 ++--- tests/ui/default_trait_access.fixed | 20 +----- tests/ui/default_trait_access.rs | 20 +----- tests/ui/doc_panics.rs | 12 +--- tests/ui/doc_panics.stderr | 12 ++-- tests/ui/float_cmp.rs | 12 +--- tests/ui/float_cmp.stderr | 12 ++-- tests/ui/float_cmp_const.rs | 6 +- tests/ui/float_cmp_const.stderr | 16 ++--- tests/ui/floating_point_abs.fixed | 30 ++------- tests/ui/floating_point_abs.rs | 72 ++++------------------ tests/ui/floating_point_abs.stderr | 70 +++++++-------------- tests/ui/if_let_some_result.fixed | 12 +--- tests/ui/if_let_some_result.rs | 12 +--- tests/ui/if_let_some_result.stderr | 6 +- tests/ui/implicit_return.fixed | 6 +- tests/ui/implicit_return.rs | 6 +- tests/ui/implicit_return.stderr | 28 ++++----- tests/ui/needless_lifetimes.rs | 6 +- tests/ui/needless_lifetimes.stderr | 36 +++++------ tests/ui/redundant_clone.fixed | 6 +- tests/ui/redundant_clone.rs | 6 +- tests/ui/redundant_clone.stderr | 28 ++++----- tests/ui/unnecessary_wraps.rs | 36 ++--------- tests/ui/unnecessary_wraps.stderr | 18 +++--- tests/ui/upper_case_acronyms.rs | 5 +- tests/ui/use_self.fixed | 6 +- tests/ui/use_self.rs | 6 +- tests/ui/use_self.stderr | 2 +- 52 files changed, 225 insertions(+), 503 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index fad3aff96cc..112c5bb14e3 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -123,13 +123,13 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType } if is_refcell_ref(cx, adt.did) { span_lint_and_note( - cx, - AWAIT_HOLDING_REFCELL_REF, - ty_cause.span, - "this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await", - ty_cause.scope_span.or(Some(span)), - "these are all the await points this ref is held through", - ); + cx, + AWAIT_HOLDING_REFCELL_REF, + ty_cause.span, + "this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await", + ty_cause.scope_span.or(Some(span)), + "these are all the await points this ref is held through", + ); } } } diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index be646cbe4d0..8e256f34684 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -145,11 +145,7 @@ fn count_digits(s: &str) -> usize { .take_while(|c| *c != 'e' && *c != 'E') .fold(0, |count, c| { // leading zeros - if c == '0' && count == 0 { - count - } else { - count + 1 - } + if c == '0' && count == 0 { count } else { count + 1 } }) } diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 129abd7d897..7040ac3191f 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -89,11 +89,7 @@ impl Finiteness { impl From for Finiteness { #[must_use] fn from(b: bool) -> Self { - if b { - Infinite - } else { - Finite - } + if b { Infinite } else { Finite } } } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index a95321ea7e2..c1f3e1d9d68 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -139,7 +139,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { self_type.to_string() ), None, - &format!("remove the inherent method from type `{}`", self_type.to_string()) + &format!("remove the inherent method from type `{}`", self_type.to_string()), ); } else { span_lint_and_help( diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 3ff9e182121..711cd5b3b15 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -3158,11 +3158,7 @@ fn detect_iter_and_into_iters<'tcx>(block: &'tcx Block<'tcx>, identifier: Ident) seen_other: false, }; visitor.visit_block(block); - if visitor.seen_other { - None - } else { - Some(visitor.uses) - } + if visitor.seen_other { None } else { Some(visitor.uses) } } fn shorten_needless_collect_span(expr: &Expr<'_>) -> Span { diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 76417aa7ed0..9ac127abe0a 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -73,11 +73,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> { } fn expr_span(&self) -> Option { - if self.found { - self.expr_span - } else { - None - } + if self.found { self.expr_span } else { None } } } diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 603071a5f4a..30fe2d6225c 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -416,11 +416,7 @@ fn erode_from_back(s: &str) -> String { break; } } - if ret.is_empty() { - s.to_string() - } else { - ret - } + if ret.is_empty() { s.to_string() } else { ret } } fn span_of_first_expr_in_block(block: &ast::Block) -> Option { diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 73a99a3a2f8..07ca196990d 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -69,15 +69,11 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec .. } = *span { - if lit { - Argument::True - } else { - Argument::False - } + if lit { Argument::True } else { Argument::False } } else { - return; // The function is called with a literal - // which is not a boolean literal. This is theoretically - // possible, but not very likely. + // The function is called with a literal which is not a boolean literal. + // This is theoretically possible, but not very likely. + return; } }, _ => Argument::Unknown, diff --git a/clippy_utils/src/camel_case.rs b/clippy_utils/src/camel_case.rs index ba1c01ebc9f..a6636e39137 100644 --- a/clippy_utils/src/camel_case.rs +++ b/clippy_utils/src/camel_case.rs @@ -25,11 +25,7 @@ pub fn until(s: &str) -> usize { return i; } } - if up { - last_i - } else { - s.len() - } + if up { last_i } else { s.len() } } /// Returns index of the last camel-case component of `s`. diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 2380ea4c7bf..fbcc6d8dc4f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1563,12 +1563,12 @@ pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { /// ``` pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { use rustc_trait_selection::traits; - let predicates = - cx.tcx - .predicates_of(did) - .predicates - .iter() - .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); + let predicates = cx + .tcx + .predicates_of(did) + .predicates + .iter() + .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); traits::impossible_predicates( cx.tcx, traits::elaborate_predicates(cx.tcx, predicates) diff --git a/clippy_utils/src/ptr.rs b/clippy_utils/src/ptr.rs index baeff08e02c..df6143edbca 100644 --- a/clippy_utils/src/ptr.rs +++ b/clippy_utils/src/ptr.rs @@ -36,11 +36,7 @@ fn extract_clone_suggestions<'tcx>( abort: false, }; visitor.visit_body(body); - if visitor.abort { - None - } else { - Some(visitor.spans) - } + if visitor.abort { None } else { Some(visitor.spans) } } struct PtrCloneVisitor<'a, 'tcx> { diff --git a/rustfmt.toml b/rustfmt.toml index f1241e74b0a..4b415a31b27 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,3 +4,4 @@ match_block_trailing_comma = true wrap_comments = true edition = "2018" error_on_line_overflow = true +version = "Two" diff --git a/tests/lint_message_convention.rs b/tests/lint_message_convention.rs index 8c07c5b242f..3f754c255b7 100644 --- a/tests/lint_message_convention.rs +++ b/tests/lint_message_convention.rs @@ -98,7 +98,9 @@ fn lint_message_convention() { eprintln!("\n\n"); }); - eprintln!("\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed."); + eprintln!( + "\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed." + ); eprintln!("Check out the rustc-dev-guide for more information:"); eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure\n\n\n"); diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs index fdf8905f812..735909887ac 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs @@ -16,7 +16,8 @@ enum Flags { FIN, } -struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of - // `GccLlvmSomething` +// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of +// `GccLlvmSomething` +struct GCCLLVMSomething; fn main() {} diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr index 1cc59dc45f2..38e30683d57 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr @@ -61,9 +61,9 @@ LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `GCCLLVMSomething` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:19:8 + --> $DIR/upper_case_acronyms.rs:21:8 | -LL | struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of +LL | struct GCCLLVMSomething; | ^^^^^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `GccllvmSomething` error: aborting due to 11 previous errors diff --git a/tests/ui/auxiliary/macro_rules.rs b/tests/ui/auxiliary/macro_rules.rs index d6ecd8568ce..d4470d3f407 100644 --- a/tests/ui/auxiliary/macro_rules.rs +++ b/tests/ui/auxiliary/macro_rules.rs @@ -23,11 +23,7 @@ macro_rules! try_err { pub fn try_err_fn() -> Result { let err: i32 = 1; // To avoid warnings during rustfix - if true { - Err(err)? - } else { - Ok(2) - } + if true { Err(err)? } else { Ok(2) } } }; } diff --git a/tests/ui/blocks_in_if_conditions.fixed b/tests/ui/blocks_in_if_conditions.fixed index 14562c4d32c..e6e40a9948c 100644 --- a/tests/ui/blocks_in_if_conditions.fixed +++ b/tests/ui/blocks_in_if_conditions.fixed @@ -4,9 +4,7 @@ #![warn(clippy::nonminimal_bool)] macro_rules! blocky { - () => {{ - true - }}; + () => {{ true }}; } macro_rules! blocky_too { @@ -34,20 +32,12 @@ fn condition_has_block() -> i32 { } fn condition_has_block_with_single_expression() -> i32 { - if true { - 6 - } else { - 10 - } + if true { 6 } else { 10 } } fn condition_is_normal() -> i32 { let x = 3; - if x == 3 { - 6 - } else { - 10 - } + if x == 3 { 6 } else { 10 } } fn condition_is_unsafe_block() { @@ -61,14 +51,15 @@ fn condition_is_unsafe_block() { fn block_in_assert() { let opt = Some(42); - assert!(opt - .as_ref() - .map(|val| { - let mut v = val * 2; - v -= 1; - v * 3 - }) - .is_some()); + assert!( + opt.as_ref() + .map(|val| { + let mut v = val * 2; + v -= 1; + v * 3 + }) + .is_some() + ); } fn main() {} diff --git a/tests/ui/blocks_in_if_conditions.rs b/tests/ui/blocks_in_if_conditions.rs index bda87650f6d..69387ff5782 100644 --- a/tests/ui/blocks_in_if_conditions.rs +++ b/tests/ui/blocks_in_if_conditions.rs @@ -4,9 +4,7 @@ #![warn(clippy::nonminimal_bool)] macro_rules! blocky { - () => {{ - true - }}; + () => {{ true }}; } macro_rules! blocky_too { @@ -34,20 +32,12 @@ fn condition_has_block() -> i32 { } fn condition_has_block_with_single_expression() -> i32 { - if { true } { - 6 - } else { - 10 - } + if { true } { 6 } else { 10 } } fn condition_is_normal() -> i32 { let x = 3; - if true && x == 3 { - 6 - } else { - 10 - } + if true && x == 3 { 6 } else { 10 } } fn condition_is_unsafe_block() { @@ -61,14 +51,15 @@ fn condition_is_unsafe_block() { fn block_in_assert() { let opt = Some(42); - assert!(opt - .as_ref() - .map(|val| { - let mut v = val * 2; - v -= 1; - v * 3 - }) - .is_some()); + assert!( + opt.as_ref() + .map(|val| { + let mut v = val * 2; + v -= 1; + v * 3 + }) + .is_some() + ); } fn main() {} diff --git a/tests/ui/blocks_in_if_conditions.stderr b/tests/ui/blocks_in_if_conditions.stderr index 9bdddc8e152..9328492733f 100644 --- a/tests/ui/blocks_in_if_conditions.stderr +++ b/tests/ui/blocks_in_if_conditions.stderr @@ -1,5 +1,5 @@ error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` - --> $DIR/blocks_in_if_conditions.rs:26:5 + --> $DIR/blocks_in_if_conditions.rs:24:5 | LL | / if { LL | | let x = 3; @@ -17,15 +17,15 @@ LL | }; if res { | error: omit braces around single expression condition - --> $DIR/blocks_in_if_conditions.rs:37:8 + --> $DIR/blocks_in_if_conditions.rs:35:8 | -LL | if { true } { +LL | if { true } { 6 } else { 10 } | ^^^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/blocks_in_if_conditions.rs:46:8 + --> $DIR/blocks_in_if_conditions.rs:40:8 | -LL | if true && x == 3 { +LL | if true && x == 3 { 6 } else { 10 } | ^^^^^^^^^^^^^^ help: try: `x == 3` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 3e7b4b390ba..36967630834 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -66,14 +66,16 @@ fn main() { } if x.is_ok() { x = Err(()); - x.unwrap(); // not unnecessary because of mutation of x - // it will always panic but the lint is not smart enough to see this (it only - // checks if conditions). + // not unnecessary because of mutation of x + // it will always panic but the lint is not smart enough to see this (it only + // checks if conditions). + x.unwrap(); } else { x = Ok(()); - x.unwrap_err(); // not unnecessary because of mutation of x - // it will always panic but the lint is not smart enough to see this (it - // only checks if conditions). + // not unnecessary because of mutation of x + // it will always panic but the lint is not smart enough to see this (it + // only checks if conditions). + x.unwrap_err(); } assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern diff --git a/tests/ui/crashes/ice-6256.rs b/tests/ui/crashes/ice-6256.rs index 5409f36b3f1..67308263dad 100644 --- a/tests/ui/crashes/ice-6256.rs +++ b/tests/ui/crashes/ice-6256.rs @@ -8,6 +8,7 @@ impl dyn TT { fn func(&self) {} } +#[rustfmt::skip] fn main() { let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types //[nll]~^ ERROR: borrowed data escapes outside of closure diff --git a/tests/ui/crashes/ice-6256.stderr b/tests/ui/crashes/ice-6256.stderr index d1a8bdc3c8d..d35d459168f 100644 --- a/tests/ui/crashes/ice-6256.stderr +++ b/tests/ui/crashes/ice-6256.stderr @@ -1,13 +1,13 @@ error[E0308]: mismatched types - --> $DIR/ice-6256.rs:12:28 + --> $DIR/ice-6256.rs:13:28 | LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types | ^^^^ lifetime mismatch | = note: expected reference `&(dyn TT + 'static)` found reference `&dyn TT` -note: the anonymous lifetime #1 defined on the body at 12:13... - --> $DIR/ice-6256.rs:12:13 +note: the anonymous lifetime #1 defined on the body at 13:13... + --> $DIR/ice-6256.rs:13:13 | LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/dbg_macro.rs b/tests/ui/dbg_macro.rs index d2df7fbd3e8..d74e2611ee1 100644 --- a/tests/ui/dbg_macro.rs +++ b/tests/ui/dbg_macro.rs @@ -1,11 +1,7 @@ #![warn(clippy::dbg_macro)] fn foo(n: u32) -> u32 { - if let Some(n) = dbg!(n.checked_sub(4)) { - n - } else { - n - } + if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } } fn factorial(n: u32) -> u32 { diff --git a/tests/ui/dbg_macro.stderr b/tests/ui/dbg_macro.stderr index b8aafe96678..bdf372af290 100644 --- a/tests/ui/dbg_macro.stderr +++ b/tests/ui/dbg_macro.stderr @@ -1,17 +1,17 @@ error: `dbg!` macro is intended as a debugging tool --> $DIR/dbg_macro.rs:4:22 | -LL | if let Some(n) = dbg!(n.checked_sub(4)) { +LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::dbg-macro` implied by `-D warnings` help: ensure to avoid having uses of it in version control | -LL | if let Some(n) = n.checked_sub(4) { +LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ^^^^^^^^^^^^^^^^ error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:12:8 + --> $DIR/dbg_macro.rs:8:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if n <= 1 { | ^^^^^^ error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:13:9 + --> $DIR/dbg_macro.rs:9:9 | LL | dbg!(1) | ^^^^^^^ @@ -33,7 +33,7 @@ LL | 1 | error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:15:9 + --> $DIR/dbg_macro.rs:11:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | n * factorial(n - 1) | error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:20:5 + --> $DIR/dbg_macro.rs:16:5 | LL | dbg!(42); | ^^^^^^^^ @@ -55,7 +55,7 @@ LL | 42; | ^^ error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:21:5 + --> $DIR/dbg_macro.rs:17:5 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | dbg!(dbg!(42)); | ^^^^^^^^^^^^^^ error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:22:14 + --> $DIR/dbg_macro.rs:18:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/default_trait_access.fixed b/tests/ui/default_trait_access.fixed index d05567a3f82..4c80cabc723 100644 --- a/tests/ui/default_trait_access.fixed +++ b/tests/ui/default_trait_access.fixed @@ -48,25 +48,7 @@ fn main() { println!( "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]", - s1, - s2, - s3, - s4, - s5, - s6, - s7, - s8, - s9, - s10, - s11, - s12, - s13, - s14, - s15, - s16, - s17, - s18, - s19, + s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, ); } diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs index 447e70c0bbb..a68b6455c04 100644 --- a/tests/ui/default_trait_access.rs +++ b/tests/ui/default_trait_access.rs @@ -48,25 +48,7 @@ fn main() { println!( "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]", - s1, - s2, - s3, - s4, - s5, - s6, - s7, - s8, - s9, - s10, - s11, - s12, - s13, - s14, - s15, - s16, - s17, - s18, - s19, + s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, ); } diff --git a/tests/ui/doc_panics.rs b/tests/ui/doc_panics.rs index 3008c2d5b85..17e72353f80 100644 --- a/tests/ui/doc_panics.rs +++ b/tests/ui/doc_panics.rs @@ -30,11 +30,7 @@ pub fn inner_body(opt: Option) { /// This needs to be documented pub fn unreachable_and_panic() { - if true { - unreachable!() - } else { - panic!() - } + if true { unreachable!() } else { panic!() } } /// This is documented @@ -84,11 +80,7 @@ pub fn todo_documented() { /// /// We still need to do this part pub fn unreachable_amd_panic_documented() { - if true { - unreachable!() - } else { - panic!() - } + if true { unreachable!() } else { panic!() } } /// This is okay because it is private diff --git a/tests/ui/doc_panics.stderr b/tests/ui/doc_panics.stderr index 287148690d2..2fa88a2f6ec 100644 --- a/tests/ui/doc_panics.stderr +++ b/tests/ui/doc_panics.stderr @@ -67,19 +67,15 @@ error: docs for function which may panic missing `# Panics` section --> $DIR/doc_panics.rs:32:1 | LL | / pub fn unreachable_and_panic() { -LL | | if true { -LL | | unreachable!() -LL | | } else { -LL | | panic!() -LL | | } +LL | | if true { unreachable!() } else { panic!() } LL | | } | |_^ | note: first possible panic found here - --> $DIR/doc_panics.rs:36:9 + --> $DIR/doc_panics.rs:33:39 | -LL | panic!() - | ^^^^^^^^ +LL | if true { unreachable!() } else { panic!() } + | ^^^^^^^^ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 5 previous errors diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index 586784b73e6..ad5d1a09c03 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -21,19 +21,11 @@ where } fn eq_fl(x: f32, y: f32) -> bool { - if x.is_nan() { - y.is_nan() - } else { - x == y - } // no error, inside "eq" fn + if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn } fn fl_eq(x: f32, y: f32) -> bool { - if x.is_nan() { - y.is_nan() - } else { - x == y - } // no error, inside "eq" fn + if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn } struct X { diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index bb4051c4662..cb5b68b2e95 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -1,5 +1,5 @@ error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:66:5 + --> $DIR/float_cmp.rs:58:5 | LL | ONE as f64 != 2.0; | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin` @@ -8,7 +8,7 @@ LL | ONE as f64 != 2.0; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:71:5 + --> $DIR/float_cmp.rs:63:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` @@ -16,7 +16,7 @@ LL | x == 1.0; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:74:5 + --> $DIR/float_cmp.rs:66:5 | LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin` @@ -24,7 +24,7 @@ LL | twice(x) != twice(ONE as f64); = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:94:5 + --> $DIR/float_cmp.rs:86:5 | LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin` @@ -32,7 +32,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` arrays - --> $DIR/float_cmp.rs:99:5 + --> $DIR/float_cmp.rs:91:5 | LL | a1 == a2; | ^^^^^^^^ @@ -40,7 +40,7 @@ LL | a1 == a2; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:100:5 + --> $DIR/float_cmp.rs:92:5 | LL | a1[0] == a2[0]; | ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin` diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 263d9a7b92d..86ce3bf3bd9 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -8,11 +8,7 @@ const ONE: f32 = 1.0; const TWO: f32 = 2.0; fn eq_one(x: f32) -> bool { - if x.is_nan() { - false - } else { - x == ONE - } // no error, inside "eq" fn + if x.is_nan() { false } else { x == ONE } // no error, inside "eq" fn } fn main() { diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 5d0455363e8..d8182cf855b 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -1,5 +1,5 @@ error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:20:5 + --> $DIR/float_cmp_const.rs:16:5 | LL | 1f32 == ONE; | ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin` @@ -8,7 +8,7 @@ LL | 1f32 == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:21:5 + --> $DIR/float_cmp_const.rs:17:5 | LL | TWO == ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` @@ -16,7 +16,7 @@ LL | TWO == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:22:5 + --> $DIR/float_cmp_const.rs:18:5 | LL | TWO != ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` @@ -24,7 +24,7 @@ LL | TWO != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:23:5 + --> $DIR/float_cmp_const.rs:19:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` @@ -32,7 +32,7 @@ LL | ONE + ONE == TWO; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:25:5 + --> $DIR/float_cmp_const.rs:21:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` @@ -40,7 +40,7 @@ LL | x as f32 == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:28:5 + --> $DIR/float_cmp_const.rs:24:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` @@ -48,7 +48,7 @@ LL | v == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:29:5 + --> $DIR/float_cmp_const.rs:25:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` @@ -56,7 +56,7 @@ LL | v != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant arrays - --> $DIR/float_cmp_const.rs:61:5 + --> $DIR/float_cmp_const.rs:57:5 | LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/floating_point_abs.fixed b/tests/ui/floating_point_abs.fixed index b623e4988e7..cea727257c4 100644 --- a/tests/ui/floating_point_abs.fixed +++ b/tests/ui/floating_point_abs.fixed @@ -42,43 +42,23 @@ fn fake_nabs3(a: A) -> A { } fn not_fake_abs1(num: f64) -> f64 { - if num > 0.0 { - num - } else { - -num - 1f64 - } + if num > 0.0 { num } else { -num - 1f64 } } fn not_fake_abs2(num: f64) -> f64 { - if num > 0.0 { - num + 1.0 - } else { - -(num + 1.0) - } + if num > 0.0 { num + 1.0 } else { -(num + 1.0) } } fn not_fake_abs3(num1: f64, num2: f64) -> f64 { - if num1 > 0.0 { - num2 - } else { - -num2 - } + if num1 > 0.0 { num2 } else { -num2 } } fn not_fake_abs4(a: A) -> f64 { - if a.a > 0.0 { - a.b - } else { - -a.b - } + if a.a > 0.0 { a.b } else { -a.b } } fn not_fake_abs5(a: A) -> f64 { - if a.a > 0.0 { - a.a - } else { - -a.b - } + if a.a > 0.0 { a.a } else { -a.b } } fn main() { diff --git a/tests/ui/floating_point_abs.rs b/tests/ui/floating_point_abs.rs index cbf9c94e41e..ba8a8f18fa2 100644 --- a/tests/ui/floating_point_abs.rs +++ b/tests/ui/floating_point_abs.rs @@ -7,59 +7,31 @@ struct A { } fn fake_abs1(num: f64) -> f64 { - if num >= 0.0 { - num - } else { - -num - } + if num >= 0.0 { num } else { -num } } fn fake_abs2(num: f64) -> f64 { - if 0.0 < num { - num - } else { - -num - } + if 0.0 < num { num } else { -num } } fn fake_abs3(a: A) -> f64 { - if a.a > 0.0 { - a.a - } else { - -a.a - } + if a.a > 0.0 { a.a } else { -a.a } } fn fake_abs4(num: f64) -> f64 { - if 0.0 >= num { - -num - } else { - num - } + if 0.0 >= num { -num } else { num } } fn fake_abs5(a: A) -> f64 { - if a.a < 0.0 { - -a.a - } else { - a.a - } + if a.a < 0.0 { -a.a } else { a.a } } fn fake_nabs1(num: f64) -> f64 { - if num < 0.0 { - num - } else { - -num - } + if num < 0.0 { num } else { -num } } fn fake_nabs2(num: f64) -> f64 { - if 0.0 >= num { - num - } else { - -num - } + if 0.0 >= num { num } else { -num } } fn fake_nabs3(a: A) -> A { @@ -70,43 +42,23 @@ fn fake_nabs3(a: A) -> A { } fn not_fake_abs1(num: f64) -> f64 { - if num > 0.0 { - num - } else { - -num - 1f64 - } + if num > 0.0 { num } else { -num - 1f64 } } fn not_fake_abs2(num: f64) -> f64 { - if num > 0.0 { - num + 1.0 - } else { - -(num + 1.0) - } + if num > 0.0 { num + 1.0 } else { -(num + 1.0) } } fn not_fake_abs3(num1: f64, num2: f64) -> f64 { - if num1 > 0.0 { - num2 - } else { - -num2 - } + if num1 > 0.0 { num2 } else { -num2 } } fn not_fake_abs4(a: A) -> f64 { - if a.a > 0.0 { - a.b - } else { - -a.b - } + if a.a > 0.0 { a.b } else { -a.b } } fn not_fake_abs5(a: A) -> f64 { - if a.a > 0.0 { - a.a - } else { - -a.b - } + if a.a > 0.0 { a.a } else { -a.b } } fn main() { diff --git a/tests/ui/floating_point_abs.stderr b/tests/ui/floating_point_abs.stderr index 74a71f2ca7c..35af70201fa 100644 --- a/tests/ui/floating_point_abs.stderr +++ b/tests/ui/floating_point_abs.stderr @@ -1,77 +1,49 @@ error: manual implementation of `abs` method --> $DIR/floating_point_abs.rs:10:5 | -LL | / if num >= 0.0 { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `num.abs()` +LL | if num >= 0.0 { num } else { -num } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:18:5 + --> $DIR/floating_point_abs.rs:14:5 | -LL | / if 0.0 < num { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `num.abs()` +LL | if 0.0 < num { num } else { -num } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:26:5 + --> $DIR/floating_point_abs.rs:18:5 | -LL | / if a.a > 0.0 { -LL | | a.a -LL | | } else { -LL | | -a.a -LL | | } - | |_____^ help: try: `a.a.abs()` +LL | if a.a > 0.0 { a.a } else { -a.a } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:34:5 + --> $DIR/floating_point_abs.rs:22:5 | -LL | / if 0.0 >= num { -LL | | -num -LL | | } else { -LL | | num -LL | | } - | |_____^ help: try: `num.abs()` +LL | if 0.0 >= num { -num } else { num } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:42:5 + --> $DIR/floating_point_abs.rs:26:5 | -LL | / if a.a < 0.0 { -LL | | -a.a -LL | | } else { -LL | | a.a -LL | | } - | |_____^ help: try: `a.a.abs()` +LL | if a.a < 0.0 { -a.a } else { a.a } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:50:5 + --> $DIR/floating_point_abs.rs:30:5 | -LL | / if num < 0.0 { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `-num.abs()` +LL | if num < 0.0 { num } else { -num } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:58:5 + --> $DIR/floating_point_abs.rs:34:5 | -LL | / if 0.0 >= num { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `-num.abs()` +LL | if 0.0 >= num { num } else { -num } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:67:12 + --> $DIR/floating_point_abs.rs:39:12 | LL | a: if a.a >= 0.0 { -a.a } else { a.a }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()` diff --git a/tests/ui/if_let_some_result.fixed b/tests/ui/if_let_some_result.fixed index 80505fd997f..62a25ce2d12 100644 --- a/tests/ui/if_let_some_result.fixed +++ b/tests/ui/if_let_some_result.fixed @@ -3,19 +3,11 @@ #![warn(clippy::if_let_some_result)] fn str_to_int(x: &str) -> i32 { - if let Ok(y) = x.parse() { - y - } else { - 0 - } + if let Ok(y) = x.parse() { y } else { 0 } } fn str_to_int_ok(x: &str) -> i32 { - if let Ok(y) = x.parse() { - y - } else { - 0 - } + if let Ok(y) = x.parse() { y } else { 0 } } #[rustfmt::skip] diff --git a/tests/ui/if_let_some_result.rs b/tests/ui/if_let_some_result.rs index ecac1357445..234ff5e9e80 100644 --- a/tests/ui/if_let_some_result.rs +++ b/tests/ui/if_let_some_result.rs @@ -3,19 +3,11 @@ #![warn(clippy::if_let_some_result)] fn str_to_int(x: &str) -> i32 { - if let Some(y) = x.parse().ok() { - y - } else { - 0 - } + if let Some(y) = x.parse().ok() { y } else { 0 } } fn str_to_int_ok(x: &str) -> i32 { - if let Ok(y) = x.parse() { - y - } else { - 0 - } + if let Ok(y) = x.parse() { y } else { 0 } } #[rustfmt::skip] diff --git a/tests/ui/if_let_some_result.stderr b/tests/ui/if_let_some_result.stderr index 6afee0f36b9..0646dd27f35 100644 --- a/tests/ui/if_let_some_result.stderr +++ b/tests/ui/if_let_some_result.stderr @@ -1,17 +1,17 @@ error: matching on `Some` with `ok()` is redundant --> $DIR/if_let_some_result.rs:6:5 | -LL | if let Some(y) = x.parse().ok() { +LL | if let Some(y) = x.parse().ok() { y } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::if-let-some-result` implied by `-D warnings` help: consider matching on `Ok(y)` and removing the call to `ok` instead | -LL | if let Ok(y) = x.parse() { +LL | if let Ok(y) = x.parse() { y } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^^^^ error: matching on `Some` with `ok()` is redundant - --> $DIR/if_let_some_result.rs:24:9 + --> $DIR/if_let_some_result.rs:16:9 | LL | if let Some(y) = x . parse() . ok () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed index 9066dc3fedf..59f7ad9c106 100644 --- a/tests/ui/implicit_return.fixed +++ b/tests/ui/implicit_return.fixed @@ -14,11 +14,7 @@ fn test_end_of_fn() -> bool { #[allow(clippy::needless_bool)] fn test_if_block() -> bool { - if true { - return true - } else { - return false - } + if true { return true } else { return false } } #[rustfmt::skip] diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index c0d70ecf502..2c1bc046515 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -14,11 +14,7 @@ fn test_end_of_fn() -> bool { #[allow(clippy::needless_bool)] fn test_if_block() -> bool { - if true { - true - } else { - false - } + if true { true } else { false } } #[rustfmt::skip] diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index fb2ec902764..3608319e5bd 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -7,61 +7,61 @@ LL | true = note: `-D clippy::implicit-return` implied by `-D warnings` error: missing `return` statement - --> $DIR/implicit_return.rs:18:9 + --> $DIR/implicit_return.rs:17:15 | -LL | true - | ^^^^ help: add `return` as shown: `return true` +LL | if true { true } else { false } + | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:20:9 + --> $DIR/implicit_return.rs:17:29 | -LL | false - | ^^^^^ help: add `return` as shown: `return false` +LL | if true { true } else { false } + | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:27:17 + --> $DIR/implicit_return.rs:23:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:28:20 + --> $DIR/implicit_return.rs:24:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:43:9 + --> $DIR/implicit_return.rs:39:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:51:13 + --> $DIR/implicit_return.rs:47:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:60:13 + --> $DIR/implicit_return.rs:56:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:78:18 + --> $DIR/implicit_return.rs:74:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:79:16 + --> $DIR/implicit_return.rs:75:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:87:5 + --> $DIR/implicit_return.rs:83:5 | LL | format!("test {}", "test") | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index 44972c8c639..bda0801e51c 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -105,11 +105,7 @@ fn fn_bound_3_cannot_elide() { // No error; multiple input refs. fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(cond: bool, x: &'a (), f: F) -> &'a () { - if cond { - x - } else { - f() - } + if cond { x } else { f() } } struct X { diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index c8a2e8b81c0..33a6de1618d 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -43,109 +43,109 @@ LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:120:5 + --> $DIR/needless_lifetimes.rs:116:5 | LL | fn self_and_out<'s>(&'s self) -> &'s u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:129:5 + --> $DIR/needless_lifetimes.rs:125:5 | LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:148:1 + --> $DIR/needless_lifetimes.rs:144:1 | LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:178:1 + --> $DIR/needless_lifetimes.rs:174:1 | LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:184:1 + --> $DIR/needless_lifetimes.rs:180:1 | LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:203:1 + --> $DIR/needless_lifetimes.rs:199:1 | LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:211:1 + --> $DIR/needless_lifetimes.rs:207:1 | LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:247:1 + --> $DIR/needless_lifetimes.rs:243:1 | LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:254:9 + --> $DIR/needless_lifetimes.rs:250:9 | LL | fn needless_lt<'a>(x: &'a u8) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:258:9 + --> $DIR/needless_lifetimes.rs:254:9 | LL | fn needless_lt<'a>(_x: &'a u8) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:271:9 + --> $DIR/needless_lifetimes.rs:267:9 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:300:5 + --> $DIR/needless_lifetimes.rs:296:5 | LL | fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:303:5 + --> $DIR/needless_lifetimes.rs:299:5 | LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:312:5 + --> $DIR/needless_lifetimes.rs:308:5 | LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:324:5 + --> $DIR/needless_lifetimes.rs:320:5 | LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:339:5 + --> $DIR/needless_lifetimes.rs:335:5 | LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:352:5 + --> $DIR/needless_lifetimes.rs:348:5 | LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:355:5 + --> $DIR/needless_lifetimes.rs:351:5 | LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index a5847e37c97..ec309109ed5 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -59,11 +59,7 @@ fn main() { #[derive(Clone)] struct Alpha; fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { - if b { - (a.clone(), a) - } else { - (Alpha, a) - } + if b { (a.clone(), a) } else { (Alpha, a) } } fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index dab8d7fb1c7..b57027456e0 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -59,11 +59,7 @@ fn main() { #[derive(Clone)] struct Alpha; fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { - if b { - (a.clone(), a.clone()) - } else { - (Alpha, a) - } + if b { (a.clone(), a.clone()) } else { (Alpha, a) } } fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index 87c219316ce..821e7934be8 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -108,61 +108,61 @@ LL | let _t = tup.0.clone(); | ^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:63:22 + --> $DIR/redundant_clone.rs:62:25 | -LL | (a.clone(), a.clone()) - | ^^^^^^^^ help: remove this +LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } + | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:63:21 + --> $DIR/redundant_clone.rs:62:24 | -LL | (a.clone(), a.clone()) - | ^ +LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } + | ^ error: redundant clone - --> $DIR/redundant_clone.rs:123:15 + --> $DIR/redundant_clone.rs:119:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:123:14 + --> $DIR/redundant_clone.rs:119:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:124:15 + --> $DIR/redundant_clone.rs:120:15 | LL | let _t = t.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:124:14 + --> $DIR/redundant_clone.rs:120:14 | LL | let _t = t.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:134:19 + --> $DIR/redundant_clone.rs:130:19 | LL | let _f = f.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:134:18 + --> $DIR/redundant_clone.rs:130:18 | LL | let _f = f.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:146:14 + --> $DIR/redundant_clone.rs:142:14 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^ help: remove this | note: cloned value is neither consumed nor mutated - --> $DIR/redundant_clone.rs:146:13 + --> $DIR/redundant_clone.rs:142:13 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^^ diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index a510263e67d..54f22e3ee6a 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -22,29 +22,17 @@ fn func2(a: bool, b: bool) -> Option { if a && b { return Some(10); } - if a { - Some(20) - } else { - Some(30) - } + if a { Some(20) } else { Some(30) } } // public fns should not be linted pub fn func3(a: bool) -> Option { - if a { - Some(1) - } else { - Some(1) - } + if a { Some(1) } else { Some(1) } } // should not be linted fn func4(a: bool) -> Option { - if a { - Some(1) - } else { - None - } + if a { Some(1) } else { None } } // should be linted @@ -64,11 +52,7 @@ fn func7() -> Result { // should not be linted fn func8(a: bool) -> Result { - if a { - Ok(1) - } else { - Err(()) - } + if a { Ok(1) } else { Err(()) } } // should not be linted @@ -143,20 +127,12 @@ fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { // should not be linted fn issue_6640_3() -> Option<()> { - if true { - Some(()) - } else { - None - } + if true { Some(()) } else { None } } // should not be linted fn issue_6640_4() -> Result<(), ()> { - if true { - Ok(()) - } else { - Err(()) - } + if true { Ok(()) } else { Err(()) } } fn main() { diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index 9a861c61a46..0e570397e2a 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -32,8 +32,7 @@ LL | / fn func2(a: bool, b: bool) -> Option { LL | | if a && b { LL | | return Some(10); LL | | } -... | -LL | | } +LL | | if a { Some(20) } else { Some(30) } LL | | } | |_^ | @@ -45,14 +44,11 @@ help: ...and then change returning expressions | LL | return 10; LL | } -LL | if a { -LL | 20 -LL | } else { -LL | 30 +LL | if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:51:1 + --> $DIR/unnecessary_wraps.rs:39:1 | LL | / fn func5() -> Option { LL | | Some(1) @@ -69,7 +65,7 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> $DIR/unnecessary_wraps.rs:61:1 + --> $DIR/unnecessary_wraps.rs:49:1 | LL | / fn func7() -> Result { LL | | Ok(1) @@ -86,7 +82,7 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:93:5 + --> $DIR/unnecessary_wraps.rs:77:5 | LL | / fn func12() -> Option { LL | | Some(1) @@ -103,7 +99,7 @@ LL | 1 | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:120:1 + --> $DIR/unnecessary_wraps.rs:104:1 | LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> { LL | | if a && b { @@ -129,7 +125,7 @@ LL | } else { ... error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:133:1 + --> $DIR/unnecessary_wraps.rs:117:1 | LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { LL | | if a && b { diff --git a/tests/ui/upper_case_acronyms.rs b/tests/ui/upper_case_acronyms.rs index fdf8905f812..735909887ac 100644 --- a/tests/ui/upper_case_acronyms.rs +++ b/tests/ui/upper_case_acronyms.rs @@ -16,7 +16,8 @@ enum Flags { FIN, } -struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of - // `GccLlvmSomething` +// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of +// `GccLlvmSomething` +struct GCCLLVMSomething; fn main() {} diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 95e7bc75431..2b22a2ed2d5 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -329,11 +329,7 @@ mod issue4140 { type To = Self; fn from(value: bool) -> Self { - if value { - 100 - } else { - 0 - } + if value { 100 } else { 0 } } } } diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 75424f34159..609625abdec 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -329,11 +329,7 @@ mod issue4140 { type To = Self; fn from(value: bool) -> Self { - if value { - 100 - } else { - 0 - } + if value { 100 } else { 0 } } } } diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index 37dfef7cfe0..e1410d2e652 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -169,7 +169,7 @@ LL | type To = T::To; | ^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:457:13 + --> $DIR/use_self.rs:453:13 | LL | A::new::(submod::B {}) | ^ help: use the applicable keyword: `Self` -- cgit 1.4.1-3-g733a5 From 1c3a3e7dc62ae3b4b84cc00c067789dae1d722c9 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 15 Mar 2021 19:55:45 -0500 Subject: Don't re-export clippy_utils::diagnostics::* --- clippy_lints/src/approx_const.rs | 2 +- clippy_lints/src/arithmetic.rs | 2 +- clippy_lints/src/as_conversions.rs | 3 +-- clippy_lints/src/asm_syntax.rs | 2 +- clippy_lints/src/assertions_on_constants.rs | 3 ++- clippy_lints/src/assign_ops.rs | 3 ++- clippy_lints/src/async_yields_async.rs | 2 +- clippy_lints/src/atomic_ordering.rs | 3 ++- clippy_lints/src/attrs.rs | 3 ++- clippy_lints/src/await_holding_invalid.rs | 3 ++- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/blacklisted_name.rs | 2 +- clippy_lints/src/blocks_in_if_conditions.rs | 3 ++- clippy_lints/src/booleans.rs | 3 ++- clippy_lints/src/bytecount.rs | 3 ++- clippy_lints/src/cargo_common_metadata.rs | 3 ++- clippy_lints/src/case_sensitive_file_extension_comparisons.rs | 2 +- clippy_lints/src/casts/cast_lossless.rs | 3 ++- clippy_lints/src/casts/cast_possible_truncation.rs | 2 +- clippy_lints/src/casts/cast_possible_wrap.rs | 3 +-- clippy_lints/src/casts/cast_precision_loss.rs | 3 +-- clippy_lints/src/casts/cast_ptr_alignment.rs | 3 ++- clippy_lints/src/casts/cast_ref_to_mut.rs | 6 ++---- clippy_lints/src/casts/cast_sign_loss.rs | 3 ++- clippy_lints/src/casts/char_lit_as_u8.rs | 3 +-- clippy_lints/src/casts/fn_to_numeric_cast.rs | 2 +- clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs | 2 +- clippy_lints/src/casts/ptr_as_ptr.rs | 3 ++- clippy_lints/src/casts/unnecessary_cast.rs | 3 ++- clippy_lints/src/checked_conversions.rs | 3 ++- clippy_lints/src/cognitive_complexity.rs | 3 ++- clippy_lints/src/collapsible_if.rs | 2 +- clippy_lints/src/collapsible_match.rs | 3 ++- clippy_lints/src/comparison_chain.rs | 3 ++- clippy_lints/src/copies.rs | 3 ++- clippy_lints/src/copy_iterator.rs | 2 +- clippy_lints/src/create_dir.rs | 3 ++- clippy_lints/src/dbg_macro.rs | 2 +- clippy_lints/src/default.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 3 +-- clippy_lints/src/dereference.rs | 3 ++- clippy_lints/src/derive.rs | 6 ++---- clippy_lints/src/disallowed_method.rs | 3 ++- clippy_lints/src/doc.rs | 5 ++--- clippy_lints/src/double_comparison.rs | 3 ++- clippy_lints/src/double_parens.rs | 2 +- clippy_lints/src/drop_forget_ref.rs | 3 ++- clippy_lints/src/duration_subsec.rs | 2 +- clippy_lints/src/else_if_without_else.rs | 3 +-- clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/eq_op.rs | 6 ++---- clippy_lints/src/erasing_op.rs | 2 +- clippy_lints/src/escape.rs | 3 +-- clippy_lints/src/eta_reduction.rs | 3 ++- clippy_lints/src/eval_order_dependence.rs | 3 ++- clippy_lints/src/excessive_bools.rs | 3 ++- clippy_lints/src/exhaustive_items.rs | 4 +--- clippy_lints/src/exit.rs | 3 ++- clippy_lints/src/explicit_write.rs | 3 ++- clippy_lints/src/fallible_impl_from.rs | 3 ++- clippy_lints/src/float_equality_without_abs.rs | 3 ++- clippy_lints/src/float_literal.rs | 3 ++- clippy_lints/src/floating_point_arithmetic.rs | 3 ++- clippy_lints/src/format.rs | 3 ++- clippy_lints/src/formatting.rs | 3 ++- clippy_lints/src/from_over_into.rs | 3 ++- clippy_lints/src/from_str_radix_10.rs | 2 +- clippy_lints/src/functions.rs | 3 ++- clippy_lints/src/future_not_send.rs | 3 ++- clippy_lints/src/get_last_with_len.rs | 3 ++- clippy_lints/src/identity_op.rs | 3 ++- clippy_lints/src/if_let_mutex.rs | 3 ++- clippy_lints/src/if_let_some_result.rs | 3 ++- clippy_lints/src/if_not_else.rs | 3 +-- clippy_lints/src/if_then_some_else_none.rs | 3 ++- clippy_lints/src/implicit_return.rs | 3 ++- clippy_lints/src/implicit_saturating_sub.rs | 3 ++- clippy_lints/src/inconsistent_struct_constructor.rs | 3 +-- clippy_lints/src/indexing_slicing.rs | 3 ++- clippy_lints/src/infinite_iter.rs | 3 ++- clippy_lints/src/inherent_impl.rs | 3 ++- clippy_lints/src/inherent_to_string.rs | 3 ++- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/int_plus_one.rs | 3 +-- clippy_lints/src/integer_division.rs | 2 +- clippy_lints/src/items_after_statements.rs | 2 +- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/len_zero.rs | 3 ++- clippy_lints/src/let_if_seq.rs | 3 ++- clippy_lints/src/let_underscore.rs | 3 ++- clippy_lints/src/lifetimes.rs | 3 ++- clippy_lints/src/literal_representation.rs | 2 +- clippy_lints/src/loops/empty_loop.rs | 3 ++- clippy_lints/src/loops/explicit_counter_loop.rs | 3 ++- clippy_lints/src/loops/explicit_into_iter_loop.rs | 2 +- clippy_lints/src/loops/explicit_iter_loop.rs | 3 ++- clippy_lints/src/loops/for_kv_map.rs | 3 ++- clippy_lints/src/loops/for_loops_over_fallibles.rs | 5 ++--- clippy_lints/src/loops/iter_next_loop.rs | 3 ++- clippy_lints/src/loops/manual_flatten.rs | 3 ++- clippy_lints/src/loops/manual_memcpy.rs | 3 ++- clippy_lints/src/loops/mut_range_bound.rs | 3 ++- clippy_lints/src/loops/needless_collect.rs | 3 ++- clippy_lints/src/loops/needless_range_loop.rs | 4 ++-- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/loops/single_element_loop.rs | 3 ++- clippy_lints/src/loops/while_immutable_condition.rs | 2 +- clippy_lints/src/loops/while_let_loop.rs | 2 +- clippy_lints/src/loops/while_let_on_iterator.rs | 2 +- clippy_lints/src/macro_use.rs | 3 ++- clippy_lints/src/main_recursion.rs | 3 ++- clippy_lints/src/manual_async_fn.rs | 3 ++- clippy_lints/src/manual_map.rs | 3 ++- clippy_lints/src/manual_non_exhaustive.rs | 3 ++- clippy_lints/src/manual_ok_or.rs | 3 ++- clippy_lints/src/manual_strip.rs | 3 ++- clippy_lints/src/manual_unwrap_or.rs | 3 ++- clippy_lints/src/map_clone.rs | 3 ++- clippy_lints/src/map_err_ignore.rs | 3 +-- clippy_lints/src/map_identity.rs | 3 ++- clippy_lints/src/map_unit_fn.rs | 3 ++- clippy_lints/src/match_on_vec_items.rs | 2 +- clippy_lints/src/matches.rs | 11 +++++++---- clippy_lints/src/mem_discriminant.rs | 3 ++- clippy_lints/src/mem_forget.rs | 3 ++- clippy_lints/src/mem_replace.rs | 6 ++---- clippy_lints/src/methods/bind_instead_of_map.rs | 6 ++---- clippy_lints/src/methods/bytes_nth.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 3 ++- clippy_lints/src/methods/clone_on_ref_ptr.rs | 3 ++- clippy_lints/src/methods/expect_fun_call.rs | 3 ++- clippy_lints/src/methods/expect_used.rs | 2 +- clippy_lints/src/methods/filetype_is_file.rs | 3 ++- clippy_lints/src/methods/filter_flat_map.rs | 3 ++- clippy_lints/src/methods/filter_map.rs | 3 ++- clippy_lints/src/methods/filter_map_flat_map.rs | 3 ++- clippy_lints/src/methods/filter_map_identity.rs | 3 ++- clippy_lints/src/methods/filter_map_map.rs | 3 ++- clippy_lints/src/methods/filter_map_next.rs | 3 ++- clippy_lints/src/methods/filter_next.rs | 3 ++- clippy_lints/src/methods/flat_map_identity.rs | 3 ++- clippy_lints/src/methods/from_iter_instead_of_collect.rs | 3 ++- clippy_lints/src/methods/get_unwrap.rs | 3 ++- clippy_lints/src/methods/implicit_clone.rs | 2 +- clippy_lints/src/methods/inefficient_to_string.rs | 3 ++- clippy_lints/src/methods/inspect_for_each.rs | 3 ++- clippy_lints/src/methods/into_iter_on_ref.rs | 3 ++- clippy_lints/src/methods/iter_cloned_collect.rs | 2 +- clippy_lints/src/methods/iter_count.rs | 3 ++- clippy_lints/src/methods/iter_next_slice.rs | 3 ++- clippy_lints/src/methods/iter_nth.rs | 2 +- clippy_lints/src/methods/iter_nth_zero.rs | 3 ++- clippy_lints/src/methods/iter_skip_next.rs | 3 ++- clippy_lints/src/methods/iterator_step_by_zero.rs | 3 ++- clippy_lints/src/methods/manual_saturating_arithmetic.rs | 3 ++- clippy_lints/src/methods/map_collect_result_unit.rs | 3 ++- clippy_lints/src/methods/map_flatten.rs | 3 ++- clippy_lints/src/methods/map_unwrap_or.rs | 3 ++- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/methods/ok_expect.rs | 2 +- clippy_lints/src/methods/option_as_ref_deref.rs | 3 ++- clippy_lints/src/methods/option_map_or_none.rs | 3 ++- clippy_lints/src/methods/option_map_unwrap_or.rs | 3 ++- clippy_lints/src/methods/or_fun_call.rs | 3 ++- clippy_lints/src/methods/search_is_some.rs | 3 ++- clippy_lints/src/methods/single_char_insert_string.rs | 2 +- clippy_lints/src/methods/single_char_pattern.rs | 2 +- clippy_lints/src/methods/single_char_push_string.rs | 2 +- clippy_lints/src/methods/skip_while_next.rs | 3 ++- clippy_lints/src/methods/string_extend_chars.rs | 3 ++- clippy_lints/src/methods/suspicious_map.rs | 3 ++- clippy_lints/src/methods/uninit_assumed_init.rs | 3 ++- clippy_lints/src/methods/unnecessary_filter_map.rs | 3 ++- clippy_lints/src/methods/unnecessary_fold.rs | 3 ++- clippy_lints/src/methods/unnecessary_lazy_eval.rs | 2 +- clippy_lints/src/methods/unwrap_used.rs | 2 +- clippy_lints/src/methods/useless_asref.rs | 3 ++- clippy_lints/src/methods/wrong_self_convention.rs | 2 +- clippy_lints/src/methods/zst_offset.rs | 2 +- clippy_lints/src/minmax.rs | 3 ++- clippy_lints/src/misc.rs | 4 ++-- clippy_lints/src/misc_early.rs | 2 +- clippy_lints/src/missing_const_for_fn.rs | 3 ++- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/modulo_arithmetic.rs | 3 ++- clippy_lints/src/multiple_crate_versions.rs | 3 ++- clippy_lints/src/mut_key.rs | 3 ++- clippy_lints/src/mut_mut.rs | 3 ++- clippy_lints/src/mut_mutex_lock.rs | 2 +- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/mutable_debug_assertion.rs | 3 ++- clippy_lints/src/mutex_atomic.rs | 2 +- clippy_lints/src/needless_arbitrary_self_type.rs | 3 ++- clippy_lints/src/needless_bool.rs | 3 ++- clippy_lints/src/needless_borrow.rs | 3 ++- clippy_lints/src/needless_borrowed_ref.rs | 2 +- clippy_lints/src/needless_continue.rs | 3 +-- clippy_lints/src/needless_pass_by_value.rs | 3 ++- clippy_lints/src/needless_question_mark.rs | 3 ++- clippy_lints/src/needless_update.rs | 2 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 3 ++- clippy_lints/src/neg_multiply.rs | 2 +- clippy_lints/src/new_without_default.rs | 3 ++- clippy_lints/src/no_effect.rs | 2 +- clippy_lints/src/non_copy_const.rs | 3 ++- clippy_lints/src/non_expressive_names.rs | 2 +- clippy_lints/src/open_options.rs | 3 ++- clippy_lints/src/option_env_unwrap.rs | 3 ++- clippy_lints/src/option_if_let_else.rs | 3 ++- clippy_lints/src/overflow_check_conditional.rs | 3 ++- clippy_lints/src/panic_in_result_fn.rs | 3 ++- clippy_lints/src/panic_unimplemented.rs | 3 ++- clippy_lints/src/partialeq_ne_impl.rs | 3 ++- clippy_lints/src/pass_by_ref_or_value.rs | 3 ++- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 3 ++- clippy_lints/src/precedence.rs | 2 +- clippy_lints/src/ptr.rs | 3 ++- clippy_lints/src/ptr_eq.rs | 3 ++- clippy_lints/src/ptr_offset_with_cast.rs | 2 +- clippy_lints/src/question_mark.rs | 3 ++- clippy_lints/src/ranges.rs | 6 ++---- clippy_lints/src/redundant_clone.rs | 3 ++- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/redundant_else.rs | 2 +- clippy_lints/src/redundant_field_names.rs | 3 ++- clippy_lints/src/redundant_pub_crate.rs | 2 +- clippy_lints/src/redundant_slicing.rs | 3 +-- clippy_lints/src/redundant_static_lifetimes.rs | 3 ++- clippy_lints/src/ref_option_ref.rs | 3 ++- clippy_lints/src/reference.rs | 3 ++- clippy_lints/src/regex.rs | 3 ++- clippy_lints/src/repeat_once.rs | 3 ++- clippy_lints/src/returns.rs | 3 ++- clippy_lints/src/self_assignment.rs | 3 ++- clippy_lints/src/semicolon_if_nothing_returned.rs | 3 ++- clippy_lints/src/serde_api.rs | 3 ++- clippy_lints/src/shadow.rs | 3 ++- clippy_lints/src/single_component_path_imports.rs | 3 ++- clippy_lints/src/size_of_in_element_count.rs | 3 ++- clippy_lints/src/slow_vector_initialization.rs | 3 ++- clippy_lints/src/stable_sort_primitive.rs | 3 ++- clippy_lints/src/strings.rs | 6 ++---- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 3 ++- clippy_lints/src/swap.rs | 3 ++- clippy_lints/src/tabs_in_doc_comments.rs | 2 +- clippy_lints/src/temporary_assignment.rs | 3 ++- clippy_lints/src/to_digit_is_some.rs | 3 ++- clippy_lints/src/to_string_in_display.rs | 3 ++- clippy_lints/src/trait_bounds.rs | 3 ++- clippy_lints/src/transmute/crosspointer_transmute.rs | 2 +- clippy_lints/src/transmute/transmute_float_to_int.rs | 3 ++- clippy_lints/src/transmute/transmute_int_to_bool.rs | 3 ++- clippy_lints/src/transmute/transmute_int_to_char.rs | 3 ++- clippy_lints/src/transmute/transmute_int_to_float.rs | 3 ++- clippy_lints/src/transmute/transmute_ptr_to_ptr.rs | 3 ++- clippy_lints/src/transmute/transmute_ptr_to_ref.rs | 3 ++- clippy_lints/src/transmute/transmute_ref_to_ref.rs | 3 ++- .../src/transmute/transmutes_expressible_as_ptr_casts.rs | 3 ++- clippy_lints/src/transmute/unsound_collection_transmute.rs | 3 ++- clippy_lints/src/transmute/useless_transmute.rs | 3 ++- clippy_lints/src/transmute/wrong_transmute.rs | 2 +- clippy_lints/src/transmuting_null.rs | 3 ++- clippy_lints/src/try_err.rs | 3 ++- clippy_lints/src/types/borrowed_box.rs | 3 ++- clippy_lints/src/types/box_vec.rs | 3 ++- clippy_lints/src/types/linked_list.rs | 3 ++- clippy_lints/src/types/mod.rs | 6 ++---- clippy_lints/src/types/option_option.rs | 3 ++- clippy_lints/src/types/rc_buffer.rs | 3 ++- clippy_lints/src/types/redundant_allocation.rs | 3 ++- clippy_lints/src/types/vec_box.rs | 3 ++- clippy_lints/src/undropped_manually_drops.rs | 3 ++- clippy_lints/src/unicode.rs | 3 ++- clippy_lints/src/unit_return_expecting_ord.rs | 3 ++- clippy_lints/src/unnamed_address.rs | 3 ++- clippy_lints/src/unnecessary_sort_by.rs | 6 +++--- clippy_lints/src/unnecessary_wraps.rs | 5 ++--- clippy_lints/src/unnested_or_patterns.rs | 3 ++- clippy_lints/src/unsafe_removed_from_name.rs | 2 +- clippy_lints/src/unused_io_amount.rs | 3 ++- clippy_lints/src/unused_self.rs | 2 +- clippy_lints/src/unused_unit.rs | 2 +- clippy_lints/src/unwrap.rs | 3 ++- clippy_lints/src/unwrap_in_result.rs | 3 ++- clippy_lints/src/upper_case_acronyms.rs | 4 ++-- clippy_lints/src/use_self.rs | 4 ++-- clippy_lints/src/useless_conversion.rs | 5 ++--- clippy_lints/src/utils/internal_lints.rs | 7 +++---- clippy_lints/src/vec.rs | 3 ++- clippy_lints/src/vec_init_then_push.rs | 3 ++- clippy_lints/src/vec_resize_to_zero.rs | 2 +- clippy_lints/src/verbose_file_reads.rs | 3 ++- clippy_lints/src/wildcard_dependencies.rs | 3 ++- clippy_lints/src/wildcard_imports.rs | 3 ++- clippy_lints/src/write.rs | 2 +- clippy_lints/src/zero_div_zero.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 3 ++- clippy_utils/src/lib.rs | 3 +-- 307 files changed, 530 insertions(+), 368 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 1d511a86c90..3d04abe094d 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 61fdf9495b9..c560f545d6a 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -1,5 +1,5 @@ use crate::consts::constant_simple; -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index c30d65bbc57..4b31e16094e 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -1,10 +1,9 @@ +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Expr, ExprKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::span_lint_and_help; - declare_clippy_lint! { /// **What it does:** Checks for usage of `as` conversions. /// diff --git a/clippy_lints/src/asm_syntax.rs b/clippy_lints/src/asm_syntax.rs index ef1f1a14afc..b970c71b753 100644 --- a/clippy_lints/src/asm_syntax.rs +++ b/clippy_lints/src/asm_syntax.rs @@ -1,6 +1,6 @@ use std::fmt; -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions}; use rustc_lint::{EarlyContext, EarlyLintPass, Lint}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 3b6f64e7769..bae4d4957a9 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -1,5 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, span_lint_and_help}; +use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call}; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, UnOp}; diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 031827e7e89..8581e176e0c 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -1,5 +1,6 @@ -use crate::utils::{eq_expr_value, get_trait_def_id, span_lint_and_then, trait_ref_of_method}; +use crate::utils::{eq_expr_value, get_trait_def_id, trait_ref_of_method}; use crate::utils::{higher, sugg}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use clippy_utils::ty::implements_trait; use if_chain::if_chain; diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index a5ed6016874..e6c7c68f91a 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 703d8a6f62b..231e74e16c0 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, span_lint_and_help}; +use crate::utils::match_def_path; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 04b0e71e4a3..6be6722375d 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -1,6 +1,7 @@ //! checks for attributes -use crate::utils::{match_panic_def_id, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::match_panic_def_id; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments}; use if_chain::if_chain; use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 14b6a156c62..3a3296c2c3d 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint_and_note}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint_and_note; use rustc_hir::def_id::DefId; use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index a4ee54076ee..2b8400344f5 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -1,6 +1,6 @@ use crate::consts::{constant, Constant}; use crate::utils::sugg::Sugg; -use crate::utils::{span_lint, span_lint_and_then}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index 153870fb416..b26ef33e056 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_data_structures::fx::FxHashSet; use rustc_hir::{Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index f43f98d1dc0..343c4821c56 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -1,4 +1,5 @@ -use crate::utils::{differing_macro_contexts, get_parent_expr, span_lint, span_lint_and_sugg}; +use crate::utils::{differing_macro_contexts, get_parent_expr}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet_block_with_applicability; use clippy_utils::ty::implements_trait; use if_chain::if_chain; diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 12a07c60438..1303613b8c4 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -1,4 +1,5 @@ -use crate::utils::{eq_expr_value, get_trait_def_id, in_macro, paths, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::{eq_expr_value, get_trait_def_id, in_macro, paths}; +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use if_chain::if_chain; diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index d02861b1b1e..c1ca787c1e5 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -1,4 +1,5 @@ -use crate::utils::{contains_name, get_pat_name, paths, single_segment_path, span_lint_and_sugg}; +use crate::utils::{contains_name, get_pat_name, paths, single_segment_path}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::match_type; use if_chain::if_chain; diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index cc2869ab495..f0ef482164a 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -2,7 +2,8 @@ use std::path::PathBuf; -use crate::utils::{run_lints, span_lint}; +use crate::utils::run_lints; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index b15fe65352a..c9ef379be56 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind, PathSegment}; diff --git a/clippy_lints/src/casts/cast_lossless.rs b/clippy_lints/src/casts/cast_lossless.rs index 62ba19c0e16..4b660188d82 100644 --- a/clippy_lints/src/casts/cast_lossless.rs +++ b/clippy_lints/src/casts/cast_lossless.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use clippy_utils::ty::is_isize_or_usize; use rustc_errors::Applicability; @@ -5,7 +6,7 @@ use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; -use crate::utils::{in_constant, span_lint_and_sugg}; +use crate::utils::in_constant; use super::{utils, CAST_LOSSLESS}; diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 522ef5348be..75d7c55b637 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -3,7 +3,7 @@ use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use super::{utils, CAST_POSSIBLE_TRUNCATION}; diff --git a/clippy_lints/src/casts/cast_possible_wrap.rs b/clippy_lints/src/casts/cast_possible_wrap.rs index 931252415ad..2c5c1d7cb46 100644 --- a/clippy_lints/src/casts/cast_possible_wrap.rs +++ b/clippy_lints/src/casts/cast_possible_wrap.rs @@ -1,10 +1,9 @@ +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::is_isize_or_usize; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::Ty; -use crate::utils::span_lint; - use super::{utils, CAST_POSSIBLE_WRAP}; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { diff --git a/clippy_lints/src/casts/cast_precision_loss.rs b/clippy_lints/src/casts/cast_precision_loss.rs index b6905c21c78..63ac8fd2dd2 100644 --- a/clippy_lints/src/casts/cast_precision_loss.rs +++ b/clippy_lints/src/casts/cast_precision_loss.rs @@ -1,10 +1,9 @@ +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::is_isize_or_usize; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; -use crate::utils::span_lint; - use super::{utils, CAST_PRECISION_LOSS}; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 87fb5557be0..6a45ec61c54 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint; use rustc_hir::{Expr, ExprKind, GenericArg}; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; @@ -6,7 +7,7 @@ use rustc_target::abi::LayoutOf; use if_chain::if_chain; -use crate::utils::{is_hir_ty_cfg_dependant, span_lint}; +use crate::utils::is_hir_ty_cfg_dependant; use super::CAST_PTR_ALIGNMENT; diff --git a/clippy_lints/src/casts/cast_ref_to_mut.rs b/clippy_lints/src/casts/cast_ref_to_mut.rs index 3fdc1c6168b..d9bf1ea58b9 100644 --- a/clippy_lints/src/casts/cast_ref_to_mut.rs +++ b/clippy_lints/src/casts/cast_ref_to_mut.rs @@ -1,11 +1,9 @@ +use clippy_utils::diagnostics::span_lint; +use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, MutTy, Mutability, TyKind, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty; -use if_chain::if_chain; - -use crate::utils::span_lint; - use super::CAST_REF_TO_MUT; pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs index 9656fbebd77..2965a840a82 100644 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ b/clippy_lints/src/casts/cast_sign_loss.rs @@ -5,7 +5,8 @@ use rustc_middle::ty::{self, Ty}; use if_chain::if_chain; use crate::consts::{constant, Constant}; -use crate::utils::{method_chain_args, sext, span_lint}; +use crate::utils::{method_chain_args, sext}; +use clippy_utils::diagnostics::span_lint; use super::CAST_SIGN_LOSS; diff --git a/clippy_lints/src/casts/char_lit_as_u8.rs b/clippy_lints/src/casts/char_lit_as_u8.rs index 75aa559359c..099a0de881f 100644 --- a/clippy_lints/src/casts/char_lit_as_u8.rs +++ b/clippy_lints/src/casts/char_lit_as_u8.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::LitKind; @@ -6,8 +7,6 @@ use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, UintTy}; -use crate::utils::span_lint_and_then; - use super::CHAR_LIT_AS_U8; pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/casts/fn_to_numeric_cast.rs b/clippy_lints/src/casts/fn_to_numeric_cast.rs index 723bfa5befe..35350d8a25b 100644 --- a/clippy_lints/src/casts/fn_to_numeric_cast.rs +++ b/clippy_lints/src/casts/fn_to_numeric_cast.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs b/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs index a3108f8a983..6287f479b5b 100644 --- a/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs +++ b/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index abfbadf3642..2c25f865cb8 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -8,8 +8,9 @@ use rustc_semver::RustcVersion; use if_chain::if_chain; +use crate::utils::meets_msrv; use crate::utils::sugg::Sugg; -use crate::utils::{meets_msrv, span_lint_and_sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use super::PTR_AS_PTR; diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index eb0ee012e6c..a84e658024a 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::{LitFloatType, LitIntType, LitKind}; @@ -7,7 +8,7 @@ use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, FloatTy, InferTy, Ty}; -use crate::utils::{numeric_literal::NumericLiteral, span_lint_and_sugg}; +use crate::utils::numeric_literal::NumericLiteral; use super::UNNECESSARY_CAST; diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 4f3daa427e3..8b62e315e04 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -1,5 +1,6 @@ //! lint on manually implemented checked conversions that could be transformed into `try_from` +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast::LitKind; @@ -10,7 +11,7 @@ use rustc_middle::lint::in_external_macro; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use crate::utils::{meets_msrv, span_lint_and_sugg, SpanlessEq}; +use crate::utils::{meets_msrv, SpanlessEq}; const CHECKED_CONVERSIONS_MSRV: RustcVersion = RustcVersion::new(1, 34, 0); diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 5b8ef01505b..8134f3af3ef 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -1,5 +1,6 @@ //! calculate cognitive complexity and warn about overly complex functions +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_opt; use clippy_utils::ty::is_type_diagnostic_item; use rustc_ast::ast::Attribute; @@ -11,7 +12,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::{sym, BytePos}; -use crate::utils::{span_lint_and_help, LimitStack}; +use crate::utils::LimitStack; declare_clippy_lint! { /// **What it does:** Checks for methods with high cognitive complexity. diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index c866f18ef3e..dbe70f90732 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -12,6 +12,7 @@ //! //! This lint is **warn** by default +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet_block, snippet_block_with_applicability}; use if_chain::if_chain; use rustc_ast::ast; @@ -20,7 +21,6 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use crate::utils::sugg::Sugg; -use crate::utils::{span_lint_and_sugg, span_lint_and_then}; declare_clippy_lint! { /// **What it does:** Checks for nested `if` statements which can be collapsed diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index 3c45525684b..5ff2518bd94 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -1,5 +1,6 @@ use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{path_to_local, span_lint_and_then, SpanlessEq}; +use crate::utils::{path_to_local, SpanlessEq}; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, QPath, StmtKind, UnOp}; diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 9843033a2e0..5411905791c 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_trait_def_id, if_sequence, parent_node_is_if_expr, paths, span_lint_and_help, SpanlessEq}; +use crate::utils::{get_trait_def_id, if_sequence, parent_node_is_if_expr, paths, SpanlessEq}; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::implements_trait; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 944aaafb46d..f86f0da6d6f 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -1,5 +1,6 @@ use crate::utils::{eq_expr_value, in_macro, search_same, SpanlessEq, SpanlessHash}; -use crate::utils::{get_parent_expr, if_sequence, span_lint_and_note}; +use crate::utils::{get_parent_expr, if_sequence}; +use clippy_utils::diagnostics::span_lint_and_note; use rustc_hir::{Block, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 434d8958da5..35079c6bedc 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_note; +use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::ty::is_copy; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/create_dir.rs b/clippy_lints/src/create_dir.rs index 0785e25b0a2..01ca2837a99 100644 --- a/clippy_lints/src/create_dir.rs +++ b/clippy_lints/src/create_dir.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint_and_sugg}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs index 3171a945eb0..286cc7e223e 100644 --- a/clippy_lints/src/dbg_macro.rs +++ b/clippy_lints/src/dbg_macro.rs @@ -1,4 +1,4 @@ -use crate::utils::{span_lint_and_help, span_lint_and_sugg}; +use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::snippet_opt; use rustc_ast::ast; use rustc_ast::tokenstream::TokenStream; diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 7d975b5a3d9..0b074c088d4 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -1,5 +1,5 @@ use crate::utils::{any_parent_is_automatically_derived, contains_name, match_def_path, paths}; -use crate::utils::{span_lint_and_note, span_lint_and_sugg}; +use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg}; use clippy_utils::source::snippet_with_macro_callsite; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index e58dcb942c6..d136db9373c 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_ast::ast::{LitFloatType, LitIntType, LitKind}; @@ -13,8 +14,6 @@ use rustc_middle::{ }; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::span_lint_and_sugg; - declare_clippy_lint! { /// **What it does:** Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type /// inference. diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index e112338dfea..62ec2f8ce48 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_parent_node, in_macro, is_allowed, span_lint_and_sugg}; +use crate::utils::{get_parent_node, in_macro, is_allowed}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::peel_mid_ty_refs; use rustc_ast::util::parser::PREC_PREFIX; diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 460fe385272..a7f2106e357 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -1,8 +1,6 @@ use crate::utils::paths; -use crate::utils::{ - get_trait_def_id, is_allowed, is_automatically_derived, match_def_path, span_lint_and_help, span_lint_and_note, - span_lint_and_then, -}; +use crate::utils::{get_trait_def_id, is_allowed, is_automatically_derived, match_def_path}; +use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_then}; use clippy_utils::ty::is_copy; use if_chain::if_chain; use rustc_hir::def_id::DefId; diff --git a/clippy_lints/src/disallowed_method.rs b/clippy_lints/src/disallowed_method.rs index 56dc6d18a58..16023bc53b0 100644 --- a/clippy_lints/src/disallowed_method.rs +++ b/clippy_lints/src/disallowed_method.rs @@ -1,4 +1,5 @@ -use crate::utils::{fn_def_id, span_lint}; +use crate::utils::fn_def_id; +use clippy_utils::diagnostics::span_lint; use rustc_data_structures::fx::FxHashSet; use rustc_hir::Expr; diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 4f3c573691e..d9952325c4b 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -1,6 +1,5 @@ -use crate::utils::{ - is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty, span_lint, span_lint_and_note, -}; +use crate::utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use if_chain::if_chain; use itertools::Itertools; diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 3de027b2cc6..549720feb2d 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -1,5 +1,6 @@ //! Lint on unnecessary double comparisons. Some examples: +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; @@ -7,7 +8,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use crate::utils::{eq_expr_value, span_lint_and_sugg}; +use crate::utils::eq_expr_value; declare_clippy_lint! { /// **What it does:** Checks for double comparisons that could be simplified to a single expression. diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index abbcaf43f41..5afdcb3c09f 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_ast::ast::{Expr, ExprKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index dd145ba6867..fe86adcec45 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint_and_note}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::ty::is_copy; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 195143d720d..40c75f568ae 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -9,7 +9,7 @@ use rustc_span::source_map::Spanned; use crate::consts::{constant, Constant}; use crate::utils::paths; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; declare_clippy_lint! { /// **What it does:** Checks for calculation of subsecond microseconds or milliseconds diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index 95123e6ff6f..26984df9539 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -1,12 +1,11 @@ //! Lint on if expressions with an else if, but without a final else branch. +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Expr, ExprKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::span_lint_and_help; - declare_clippy_lint! { /// **What it does:** Checks for usage of if expressions with an `else if` branch, /// but without a final `else` branch. diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 077c3b75fb8..c92984a9834 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -1,6 +1,6 @@ //! lint when there is an enum with no variants -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 93723219594..cc774831491 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -1,6 +1,6 @@ -use crate::utils::span_lint_and_then; use crate::utils::SpanlessEq; use crate::utils::{get_item_name, paths}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability}; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use if_chain::if_chain; diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index aa235642ac3..7a98ae39d3a 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -2,7 +2,7 @@ //! don't fit into an `i32` use crate::consts::{miri_to_const, Constant}; -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::util::IntTypeExt; diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 660131cf176..d2d8acb443b 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -1,7 +1,7 @@ //! lint on enum variants that are prefixed or suffixed by the same characters use crate::utils::camel_case; -use crate::utils::{span_lint, span_lint_and_help}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use clippy_utils::source::is_present_in_source; use rustc_ast::ast::{EnumDef, Item, ItemKind, VisibilityKind}; use rustc_lint::{EarlyContext, EarlyLintPass, Lint}; diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 0a5917c10ea..1b2f66fb628 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -1,7 +1,5 @@ -use crate::utils::{ - ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of, multispan_sugg, span_lint, - span_lint_and_then, -}; +use crate::utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of}; +use clippy_utils::diagnostics::{multispan_sugg, span_lint, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::{implements_trait, is_copy}; use if_chain::if_chain; diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index dbd1ff514f0..59602616781 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -1,10 +1,10 @@ +use clippy_utils::diagnostics::span_lint; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use crate::consts::{constant_simple, Constant}; -use crate::utils::span_lint; declare_clippy_lint! { /// **What it does:** Checks for erasing operations, e.g., `x * 0`. diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index a7258eea0ad..06da14a9844 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::contains_ty; use rustc_hir::intravisit; use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node}; @@ -11,8 +12,6 @@ use rustc_target::abi::LayoutOf; use rustc_target::spec::abi::Abi; use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; -use crate::utils::span_lint; - #[derive(Copy, Clone)] pub struct BoxedLocal { pub too_large_for_stack: u64, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index e8d5b992b63..2557e9f2796 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::higher; use clippy_utils::higher::VecArgs; use clippy_utils::source::snippet_opt; @@ -10,7 +11,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{is_adjusted, iter_input_pats, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::{is_adjusted, iter_input_pats}; declare_clippy_lint! { /// **What it does:** Checks for closures which just call another function where diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 83cee11c3a8..3711ba4a7ee 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_parent_expr, path_to_local, path_to_local_id, span_lint, span_lint_and_note}; +use crate::utils::{get_parent_expr, path_to_local, path_to_local_id}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 6a85b57af07..683e0435351 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -1,4 +1,5 @@ -use crate::utils::{attr_by_name, in_macro, match_path_ast, span_lint_and_help}; +use crate::utils::{attr_by_name, in_macro, match_path_ast}; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index 5e31072523d..60ad2e8ee14 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -1,14 +1,12 @@ +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::indent_of; use if_chain::if_chain; - use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -use crate::utils::span_lint_and_then; - declare_clippy_lint! { /// **What it does:** Warns on any exported `enum`s that are not tagged `#[non_exhaustive]` /// diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 91585927000..adfb644b199 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_entrypoint_fn, match_def_path, paths, span_lint}; +use crate::utils::{is_entrypoint_fn, match_def_path, paths}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index f8038d06e50..0861cba4675 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_expn_of, match_function_call, paths, span_lint, span_lint_and_sugg}; +use crate::utils::{is_expn_of, match_function_call, paths}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index cc4e570956b..5efe465a667 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_expn_of, match_panic_def_id, method_chain_args, span_lint_and_then}; +use crate::utils::{is_expn_of, match_panic_def_id, method_chain_args}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_hir as hir; diff --git a/clippy_lints/src/float_equality_without_abs.rs b/clippy_lints/src/float_equality_without_abs.rs index c1c08597ee6..b3593d328cc 100644 --- a/clippy_lints/src/float_equality_without_abs.rs +++ b/clippy_lints/src/float_equality_without_abs.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint_and_then, sugg}; +use crate::utils::{match_def_path, paths, sugg}; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_ast::util::parser::AssocOp; use rustc_errors::Applicability; diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 8e256f34684..6446fe62a64 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -1,4 +1,5 @@ -use crate::utils::{numeric_literal, span_lint_and_sugg}; +use crate::utils::numeric_literal; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 086a791520f..8b53384ecbd 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -2,7 +2,8 @@ use crate::consts::{ constant, constant_simple, Constant, Constant::{Int, F32, F64}, }; -use crate::utils::{eq_expr_value, get_parent_expr, numeric_literal, span_lint_and_sugg, sugg}; +use crate::utils::{eq_expr_value, get_parent_expr, numeric_literal, sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp}; diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index c0048bb2175..db27225707d 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -1,5 +1,6 @@ use crate::utils::paths; -use crate::utils::{is_expn_of, last_path_segment, match_def_path, match_function_call, span_lint_and_then}; +use crate::utils::{is_expn_of, last_path_segment, match_def_path, match_function_call}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 590de04717a..4dadd2ba936 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -1,4 +1,5 @@ -use crate::utils::{differing_macro_contexts, span_lint_and_help, span_lint_and_note}; +use crate::utils::differing_macro_contexts; +use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note}; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index b644bb07990..5eea4d14759 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -1,5 +1,6 @@ use crate::utils::paths::INTO; -use crate::utils::{match_def_path, meets_msrv, span_lint_and_help}; +use crate::utils::{match_def_path, meets_msrv}; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index b92c8ccfb1b..b9a44f26381 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; @@ -7,7 +8,6 @@ use rustc_middle::ty::Ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; -use crate::utils::span_lint_and_sugg; use crate::utils::sugg::Sugg; declare_clippy_lint! { diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 104c692dcec..37288d7a0b2 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -1,7 +1,8 @@ use crate::utils::{ attr_by_name, attrs::is_proc_macro, is_trait_impl_item, iter_input_pats, match_def_path, must_use_attr, - path_to_local, return_ty, span_lint, span_lint_and_help, span_lint_and_then, trait_ref_of_method, + path_to_local, return_ty, trait_ref_of_method, }; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_then}; use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::{is_must_use_ty, is_type_diagnostic_item, type_is_unsafe_function}; use if_chain::if_chain; diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 9e1a8864a3e..36960e7f51b 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -1,4 +1,5 @@ use crate::utils; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; @@ -84,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { fulfillment_cx.select_all_or_error(&infcx) }); if let Err(send_errors) = send_result { - utils::span_lint_and_then( + span_lint_and_then( cx, FUTURE_NOT_SEND, span, diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index 875cd33bc8f..6f14ede0ecb 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -1,6 +1,7 @@ //! lint on using `x.get(x.len() - 1)` instead of `x.last()` -use crate::utils::{span_lint_and_sugg, SpanlessEq}; +use crate::utils::SpanlessEq; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index fc93864c74a..385ea020328 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -7,7 +7,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use crate::consts::{constant_simple, Constant}; -use crate::utils::{clip, span_lint, unsext}; +use crate::utils::{clip, unsext}; +use clippy_utils::diagnostics::span_lint; declare_clippy_lint! { /// **What it does:** Checks for identity operations, e.g., `x + 0`. diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index f53d1b1cf3b..c2ec8b3ffd1 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -1,4 +1,5 @@ -use crate::utils::{span_lint_and_help, SpanlessEq}; +use crate::utils::SpanlessEq; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_hir::intravisit::{self as visit, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 9f7ca95a8f3..59094d1147a 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -1,4 +1,5 @@ -use crate::utils::{method_chain_args, span_lint_and_sugg}; +use crate::utils::method_chain_args; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index b86d2e76656..c56f67df061 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -1,13 +1,12 @@ //! lint on if branches that could be swapped so no `!` operation is necessary //! on the condition +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::span_lint_and_help; - declare_clippy_lint! { /// **What it does:** Checks for usage of `!` or `!=` in an if condition with an /// else branch. diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index 7e1807786ee..c4e87300b7b 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -1,4 +1,5 @@ use crate::utils; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_with_macro_callsite; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; @@ -100,7 +101,7 @@ impl LateLintPass<'_> for IfThenSomeElseNone { cond_snip, closure_body, ); - utils::span_lint_and_help( + span_lint_and_help( cx, IF_THEN_SOME_ELSE_NONE, expr.span, diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index e86bd49251d..70ea9a92279 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_panic_def_id, span_lint_and_then}; +use crate::utils::match_panic_def_id; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 16e162badb5..3d2798f3fb4 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, match_qpath, span_lint_and_sugg, SpanlessEq}; +use crate::utils::{in_macro, match_qpath, SpanlessEq}; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 4762d5d40f3..b7986da7820 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_data_structures::fx::FxHashMap; @@ -7,8 +8,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::Symbol; -use crate::utils::span_lint_and_sugg; - declare_clippy_lint! { /// **What it does:** Checks for struct constructors where all fields are shorthand and /// the order of the field init shorthand in the constructor is inconsistent diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index c919ec097a2..4c0f976f79a 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -1,7 +1,8 @@ //! lint on indexing and slicing operations use crate::consts::{constant, Constant}; -use crate::utils::{higher, span_lint, span_lint_and_help}; +use crate::utils::higher; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use rustc_ast::ast::RangeLimits; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 6bce205ec3a..addd95c6eae 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -1,9 +1,10 @@ +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::{implements_trait, match_type}; use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{get_trait_def_id, higher, match_qpath, paths, span_lint}; +use crate::utils::{get_trait_def_id, higher, match_qpath, paths}; declare_clippy_lint! { /// **What it does:** Checks for iteration that is guaranteed to be infinite. diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 005c461f105..f838ce190dc 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -1,6 +1,7 @@ //! lint on inherent implementations -use crate::utils::{in_macro, span_lint_and_then}; +use crate::utils::in_macro; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_data_structures::fx::FxHashMap; use rustc_hir::{def_id, Crate, Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 9207413cd69..6b29feeb4ed 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use if_chain::if_chain; use rustc_hir::{ImplItem, ImplItemKind}; @@ -5,7 +6,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -use crate::utils::{get_trait_def_id, paths, return_ty, span_lint_and_help, trait_ref_of_method}; +use crate::utils::{get_trait_def_id, paths, return_ty, trait_ref_of_method}; declare_clippy_lint! { /// **What it does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`. diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 00acbd6cc3f..87fe5123cf6 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -1,7 +1,7 @@ //! checks for `#[inline]` on trait methods without bodies -use crate::utils::span_lint_and_then; use crate::utils::sugg::DiagnosticBuilderExt; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::ast::Attribute; use rustc_errors::Applicability; use rustc_hir::{TraitFn, TraitItem, TraitItemKind}; diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 9eae653dd67..c4a1222b51f 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -1,13 +1,12 @@ //! lint on blocks unnecessarily using >= with a + 1 or - 1 +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use rustc_ast::ast::{BinOpKind, Expr, ExprKind, Lit, LitKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::span_lint_and_sugg; - declare_clippy_lint! { /// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block /// diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs index 39b4605e72f..e5482f675e7 100644 --- a/clippy_lints/src/integer_division.rs +++ b/clippy_lints/src/integer_division.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index 0927d218446..c69571f32a2 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -1,6 +1,6 @@ //! lint when items are used after statements -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_ast::ast::{Block, ItemKind, StmtKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index a76595ed089..48dc5fefe99 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -1,5 +1,5 @@ use crate::rustc_target::abi::LayoutOf; -use crate::utils::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index cbb5192bfd9..76584dc1822 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -1,6 +1,6 @@ //! lint when there is a large size difference between variants on an enum -use crate::utils::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind, VariantData}; diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index ceae4243e63..c46b98022c6 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; @@ -7,7 +8,6 @@ use rustc_middle::ty::{self, ConstKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use crate::rustc_target::abi::LayoutOf; -use crate::utils::span_lint_and_help; declare_clippy_lint! { /// **What it does:** Checks for local arrays that may be too large. diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index e758a269fbe..a644a4113ae 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_item_name, get_parent_as_impl, is_allowed, span_lint, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::{get_item_name, get_parent_as_impl, is_allowed}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast::LitKind; diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 7059ba21207..4b7e02398fb 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -1,4 +1,5 @@ -use crate::utils::{path_to_local_id, span_lint_and_then, visitors::LocalUsedVisitor}; +use crate::utils::{path_to_local_id, visitors::LocalUsedVisitor}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 2da7137b48b..eee2503b481 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_must_use_ty, match_type}; use if_chain::if_chain; use rustc_hir::{Local, PatKind}; @@ -6,7 +7,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{is_must_use_func_call, paths, span_lint_and_help}; +use crate::utils::{is_must_use_func_call, paths}; declare_clippy_lint! { /// **What it does:** Checks for `let _ = ` diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 33ff01a30e8..0848aaed815 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, span_lint, trait_ref_of_method}; +use crate::utils::{in_macro, trait_ref_of_method}; +use clippy_utils::diagnostics::span_lint; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::intravisit::{ walk_fn_decl, walk_generic_param, walk_generics, walk_item, walk_param_bound, walk_poly_trait_ref, walk_ty, diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 8bc7bf37ef1..dd303bc0a01 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -4,8 +4,8 @@ use crate::utils::{ in_macro, numeric_literal::{NumericLiteral, Radix}, - span_lint_and_sugg, }; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind, Lit, LitKind}; diff --git a/clippy_lints/src/loops/empty_loop.rs b/clippy_lints/src/loops/empty_loop.rs index 43e85538f28..d52a061fc8f 100644 --- a/clippy_lints/src/loops/empty_loop.rs +++ b/clippy_lints/src/loops/empty_loop.rs @@ -1,5 +1,6 @@ use super::EMPTY_LOOP; -use crate::utils::{is_in_panic_handler, is_no_std_crate, span_lint_and_help}; +use crate::utils::{is_in_panic_handler, is_no_std_crate}; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{Block, Expr}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/loops/explicit_counter_loop.rs b/clippy_lints/src/loops/explicit_counter_loop.rs index 1f6d48fe915..87ce4e4c20c 100644 --- a/clippy_lints/src/loops/explicit_counter_loop.rs +++ b/clippy_lints/src/loops/explicit_counter_loop.rs @@ -1,7 +1,8 @@ use super::{ get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP, }; -use crate::utils::{get_enclosing_block, is_integer_const, span_lint_and_sugg}; +use crate::utils::{get_enclosing_block, is_integer_const}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/explicit_into_iter_loop.rs b/clippy_lints/src/loops/explicit_into_iter_loop.rs index e5b3dc7aad7..4871a031187 100644 --- a/clippy_lints/src/loops/explicit_into_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_into_iter_loop.rs @@ -1,5 +1,5 @@ use super::EXPLICIT_INTO_ITER_LOOP; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index d2000d80ac1..259e95e5ef4 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -1,5 +1,6 @@ use super::EXPLICIT_ITER_LOOP; -use crate::utils::{match_trait_method, paths, span_lint_and_sugg}; +use crate::utils::{match_trait_method, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/for_kv_map.rs b/clippy_lints/src/loops/for_kv_map.rs index 19a68dd78d1..bf037f392e0 100644 --- a/clippy_lints/src/loops/for_kv_map.rs +++ b/clippy_lints/src/loops/for_kv_map.rs @@ -1,6 +1,7 @@ use super::FOR_KV_MAP; use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{multispan_sugg, paths, span_lint_and_then, sugg}; +use crate::utils::{paths, sugg}; +use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind}; diff --git a/clippy_lints/src/loops/for_loops_over_fallibles.rs b/clippy_lints/src/loops/for_loops_over_fallibles.rs index 5140448592d..d49b0517dcf 100644 --- a/clippy_lints/src/loops/for_loops_over_fallibles.rs +++ b/clippy_lints/src/loops/for_loops_over_fallibles.rs @@ -1,8 +1,7 @@ +use super::FOR_LOOPS_OVER_FALLIBLES; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; - -use super::FOR_LOOPS_OVER_FALLIBLES; -use crate::utils::span_lint_and_help; use rustc_hir::{Expr, Pat}; use rustc_lint::LateContext; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/loops/iter_next_loop.rs b/clippy_lints/src/loops/iter_next_loop.rs index d6b40fa9fa8..27a03562800 100644 --- a/clippy_lints/src/loops/iter_next_loop.rs +++ b/clippy_lints/src/loops/iter_next_loop.rs @@ -1,9 +1,10 @@ use super::ITER_NEXT_LOOP; +use clippy_utils::diagnostics::span_lint; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_span::sym; -use crate::utils::{is_trait_method, span_lint}; +use crate::utils::is_trait_method; pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, expr: &Expr<'_>) -> bool { if is_trait_method(cx, arg, sym::Iterator) { diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 3d3ae6f3152..43580d6071a 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -1,6 +1,7 @@ use super::utils::make_iterator_snippet; use super::MANUAL_FLATTEN; -use crate::utils::{is_ok_ctor, is_some_ctor, path_to_local_id, span_lint_and_then}; +use crate::utils::{is_ok_ctor, is_some_ctor, path_to_local_id}; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatKind, QPath, StmtKind}; diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index c9c25641160..ff68d136999 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -1,6 +1,7 @@ use super::{get_span_of_entire_for_loop, IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY}; use crate::utils::sugg::Sugg; -use crate::utils::{get_enclosing_block, higher, path_to_local, span_lint_and_sugg, sugg}; +use crate::utils::{get_enclosing_block, higher, path_to_local, sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 3ae592950f1..175aee53a9a 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -1,5 +1,6 @@ use super::MUT_RANGE_BOUND; -use crate::utils::{higher, path_to_local, span_lint}; +use crate::utils::{higher, path_to_local}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir::{BindingAnnotation, Expr, HirId, Node, PatKind}; use rustc_infer::infer::TyCtxtInferExt; diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index 59f7b23af75..a3b731eefa0 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -1,6 +1,7 @@ use super::NEEDLESS_COLLECT; use crate::utils::sugg::Sugg; -use crate::utils::{is_trait_method, path_to_local_id, paths, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::{is_trait_method, path_to_local_id, paths}; +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use if_chain::if_chain; diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 674cb34c37b..ca679d7ebe1 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -1,9 +1,9 @@ use super::NEEDLESS_RANGE_LOOP; use crate::utils::visitors::LocalUsedVisitor; use crate::utils::{ - contains_name, higher, is_integer_const, match_trait_method, multispan_sugg, path_to_local_id, paths, - span_lint_and_then, sugg, SpanlessEq, + contains_name, higher, is_integer_const, match_trait_method, path_to_local_id, paths, sugg, SpanlessEq, }; +use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::has_iter_method; use if_chain::if_chain; diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 45e1001d755..82ec2635aeb 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -1,5 +1,5 @@ use super::NEVER_LOOP; -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{Block, Expr, ExprKind, HirId, InlineAsmOperand, Stmt, StmtKind}; use rustc_lint::LateContext; use std::iter::{once, Iterator}; diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 255d6de4a36..849d7ec718c 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -1,5 +1,5 @@ use super::SAME_ITEM_PUSH; -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_with_macro_callsite; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use if_chain::if_chain; diff --git a/clippy_lints/src/loops/single_element_loop.rs b/clippy_lints/src/loops/single_element_loop.rs index 4f83191d919..172eb963ae3 100644 --- a/clippy_lints/src/loops/single_element_loop.rs +++ b/clippy_lints/src/loops/single_element_loop.rs @@ -1,5 +1,6 @@ use super::{get_span_of_entire_for_loop, SINGLE_ELEMENT_LOOP}; -use crate::utils::{single_segment_path, span_lint_and_sugg}; +use crate::utils::single_segment_path; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{indent_of, snippet}; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/while_immutable_condition.rs b/clippy_lints/src/loops/while_immutable_condition.rs index 05e0a722563..a037a06de81 100644 --- a/clippy_lints/src/loops/while_immutable_condition.rs +++ b/clippy_lints/src/loops/while_immutable_condition.rs @@ -1,7 +1,7 @@ use super::WHILE_IMMUTABLE_CONDITION; use crate::consts::constant; -use crate::utils::span_lint_and_then; use crate::utils::usage::mutated_variables; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::{DefKind, Res}; diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index dbd9126861f..ffe8c0c5494 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -1,5 +1,5 @@ use super::WHILE_LET_LOOP; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind, MatchSource, StmtKind}; diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index ccabe586c2b..29ad9e735cc 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -3,8 +3,8 @@ use super::WHILE_LET_ON_ITERATOR; use crate::utils::usage::mutated_variables; use crate::utils::{ get_enclosing_block, is_refutable, is_trait_method, last_path_segment, path_to_local, path_to_local_id, - span_lint_and_sugg, }; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::implements_trait; use if_chain::if_chain; diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 637f10f6609..92f95645734 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, span_lint_and_sugg}; +use crate::utils::in_macro; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use hir::def::{DefKind, Res}; use if_chain::if_chain; diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 5db2968e42c..6c0308cbd92 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -1,10 +1,11 @@ +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_hir::{Crate, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use crate::utils::{is_entrypoint_fn, is_no_std_crate, span_lint_and_help}; +use crate::utils::{is_entrypoint_fn, is_no_std_crate}; declare_clippy_lint! { /// **What it does:** Checks for recursion using the entrypoint. diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index ebc493c0f7e..1db5cf56962 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -1,5 +1,6 @@ +use crate::utils::match_function_call; use crate::utils::paths::FUTURE_FROM_GENERATOR; -use crate::utils::{match_function_call, span_lint_and_then}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt}; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index 3896645ca7d..fd563bec769 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -1,8 +1,9 @@ use crate::{ map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF, - utils::{is_allowed, match_def_path, match_var, paths, peel_hir_expr_refs, span_lint_and_sugg}, + utils::{is_allowed, match_def_path, match_var, paths, peel_hir_expr_refs}, }; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::ty::{can_partially_move_ty, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable}; use rustc_ast::util::parser::PREC_POSTFIX; diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 0b8c049b466..705c1ec1859 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -1,4 +1,5 @@ -use crate::utils::{meets_msrv, span_lint_and_then}; +use crate::utils::meets_msrv; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantData, VisibilityKind}; diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index f436eccc0dc..a1e5c752f83 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_qpath, path_to_local_id, paths, span_lint_and_sugg}; +use crate::utils::{match_qpath, path_to_local_id, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 3bfca8bea40..bc4e255b03d 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -1,6 +1,7 @@ use crate::consts::{constant, Constant}; use crate::utils::usage::mutated_variables; -use crate::utils::{eq_expr_value, higher, match_def_path, meets_msrv, multispan_sugg, paths, span_lint_and_then}; +use crate::utils::{eq_expr_value, higher, match_def_path, meets_msrv, paths}; +use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_ast::ast::LitKind; diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 7a4040539e3..0e030e0e261 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -1,6 +1,7 @@ use crate::consts::constant_simple; use crate::utils; use crate::utils::{path_to_local_id, sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; @@ -112,7 +113,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { then { let reindented_or_body = reindent_multiline(or_body_snippet.into(), true, Some(indent)); - utils::span_lint_and_sugg( + span_lint_and_sugg( cx, MANUAL_UNWRAP_OR, expr.span, &format!("this pattern reimplements `{}`", case.unwrap_fn_path()), diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index e10d7647bcf..fd39052871b 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -1,5 +1,6 @@ use crate::utils::is_trait_method; -use crate::utils::{remove_blocks, span_lint_and_sugg}; +use crate::utils::remove_blocks; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_copy, is_type_diagnostic_item}; use if_chain::if_chain; diff --git a/clippy_lints/src/map_err_ignore.rs b/clippy_lints/src/map_err_ignore.rs index 76fe8e776ea..a6a63961be5 100644 --- a/clippy_lints/src/map_err_ignore.rs +++ b/clippy_lints/src/map_err_ignore.rs @@ -1,5 +1,4 @@ -use crate::utils::span_lint_and_help; - +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{CaptureBy, Expr, ExprKind, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/map_identity.rs b/clippy_lints/src/map_identity.rs index 79570367ed9..84ec23c4e2f 100644 --- a/clippy_lints/src/map_identity.rs +++ b/clippy_lints/src/map_identity.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_adjusted, is_trait_method, match_path, match_var, paths, remove_blocks, span_lint_and_sugg}; +use crate::utils::{is_adjusted, is_trait_method, match_path, match_var, paths, remove_blocks}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 24bcc808585..3bd4a965765 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -1,4 +1,5 @@ -use crate::utils::{iter_input_pats, method_chain_args, span_lint_and_then}; +use crate::utils::{iter_input_pats, method_chain_args}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index 57dcd8709b8..ccaa5e98c83 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; use if_chain::if_chain; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 4ae1ce977f4..1aa09b82822 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -2,11 +2,13 @@ use crate::consts::{constant, miri_to_const, Constant}; use crate::utils::sugg::Sugg; use crate::utils::visitors::LocalUsedVisitor; use crate::utils::{ - get_parent_expr, in_macro, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath, meets_msrv, multispan_sugg, - path_to_local, path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, remove_blocks, span_lint_and_help, - span_lint_and_note, span_lint_and_sugg, span_lint_and_then, strip_pat_refs, + get_parent_expr, in_macro, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath, meets_msrv, path_to_local, + path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, remove_blocks, strip_pat_refs, }; use crate::utils::{paths, search_same, SpanlessEq, SpanlessHash}; +use clippy_utils::diagnostics::{ + multispan_sugg, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, +}; use clippy_utils::source::{expr_block, indent_of, snippet, snippet_block, snippet_opt, snippet_with_applicability}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs}; use if_chain::if_chain; @@ -1614,7 +1616,8 @@ where mod redundant_pattern_match { use super::REDUNDANT_PATTERN_MATCHING; - use crate::utils::{is_trait_method, match_qpath, paths, span_lint_and_then}; + use crate::utils::{is_trait_method, match_qpath, paths}; + use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_ast::ast::LitKind; diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index fbdc0cdb2d8..85353d4cdde 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint_and_then}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::walk_ptrs_ty_depth; use if_chain::if_chain; diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index d34f9761e26..1a8cb82514b 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index bf3f6f7f830..87cb66a6770 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -1,7 +1,5 @@ -use crate::utils::{ - in_macro, match_def_path, match_qpath, meets_msrv, paths, span_lint_and_help, span_lint_and_sugg, - span_lint_and_then, -}; +use crate::utils::{in_macro, match_def_path, match_qpath, meets_msrv, paths}; +use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::is_diagnostic_assoc_item; use clippy_utils::source::{snippet, snippet_with_applicability}; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 99b3be67f18..7d6104ebb7f 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -1,8 +1,6 @@ use super::{contains_return, BIND_INSTEAD_OF_MAP}; -use crate::utils::{ - in_macro, match_qpath, method_calls, multispan_sugg_with_applicability, paths, remove_blocks, span_lint_and_sugg, - span_lint_and_then, visitors::find_all_ret_expressions, -}; +use crate::utils::{in_macro, match_qpath, method_calls, paths, remove_blocks, visitors::find_all_ret_expressions}; +use clippy_utils::diagnostics::{multispan_sugg_with_applicability, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet, snippet_with_macro_callsite}; use clippy_utils::ty::match_type; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/bytes_nth.rs b/clippy_lints/src/methods/bytes_nth.rs index f81e9a8c524..4f88f80a304 100644 --- a/clippy_lints/src/methods/bytes_nth.rs +++ b/clippy_lints/src/methods/bytes_nth.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 954d589a47e..d1c7789a241 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -1,4 +1,5 @@ -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_copy; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/clone_on_ref_ptr.rs b/clippy_lints/src/methods/clone_on_ref_ptr.rs index 90ecb2382e7..b49ae42b12f 100644 --- a/clippy_lints/src/methods/clone_on_ref_ptr.rs +++ b/clippy_lints/src/methods/clone_on_ref_ptr.rs @@ -1,4 +1,5 @@ -use crate::utils::{paths, span_lint_and_sugg}; +use crate::utils::paths; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_macro_callsite; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 9e96d571337..1c673c11d65 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_expn_of, span_lint_and_sugg}; +use crate::utils::is_expn_of; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/expect_used.rs b/clippy_lints/src/methods/expect_used.rs index 37c41194b4a..64531b29ade 100644 --- a/clippy_lints/src/methods/expect_used.rs +++ b/clippy_lints/src/methods/expect_used.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_type_diagnostic_item; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/filetype_is_file.rs b/clippy_lints/src/methods/filetype_is_file.rs index 791fe3647cb..005c94a6018 100644 --- a/clippy_lints/src/methods/filetype_is_file.rs +++ b/clippy_lints/src/methods/filetype_is_file.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_parent_expr, paths, span_lint_and_help}; +use crate::utils::{get_parent_expr, paths}; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::match_type; use if_chain::if_chain; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/filter_flat_map.rs b/clippy_lints/src/methods/filter_flat_map.rs index 42f05aa0b3a..4820bb137c1 100644 --- a/clippy_lints/src/methods/filter_flat_map.rs +++ b/clippy_lints/src/methods/filter_flat_map.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_help}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 964c4903ed2..af91370df20 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, path_to_local_id, span_lint_and_sugg, SpanlessEq}; +use crate::utils::{is_trait_method, path_to_local_id, SpanlessEq}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/filter_map_flat_map.rs b/clippy_lints/src/methods/filter_map_flat_map.rs index e113f3f71b1..5294ef97528 100644 --- a/clippy_lints/src/methods/filter_map_flat_map.rs +++ b/clippy_lints/src/methods/filter_map_flat_map.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_help}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/filter_map_identity.rs b/clippy_lints/src/methods/filter_map_identity.rs index 5f627b42abc..4461baf4f7c 100644 --- a/clippy_lints/src/methods/filter_map_identity.rs +++ b/clippy_lints/src/methods/filter_map_identity.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, match_qpath, path_to_local_id, paths, span_lint_and_sugg}; +use crate::utils::{is_trait_method, match_qpath, path_to_local_id, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/filter_map_map.rs b/clippy_lints/src/methods/filter_map_map.rs index 2e704c4c555..8f17350054b 100644 --- a/clippy_lints/src/methods/filter_map_map.rs +++ b/clippy_lints/src/methods/filter_map_map.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_help}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/filter_map_next.rs b/clippy_lints/src/methods/filter_map_next.rs index ed75315b52c..8fbadd1d457 100644 --- a/clippy_lints/src/methods/filter_map_next.rs +++ b/clippy_lints/src/methods/filter_map_next.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, meets_msrv, span_lint, span_lint_and_sugg}; +use crate::utils::{is_trait_method, meets_msrv}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index 097f9fdf2c4..af16ea19007 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint, span_lint_and_sugg}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/flat_map_identity.rs b/clippy_lints/src/methods/flat_map_identity.rs index 19ddceeccce..669ac1f743f 100644 --- a/clippy_lints/src/methods/flat_map_identity.rs +++ b/clippy_lints/src/methods/flat_map_identity.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, match_qpath, paths, span_lint_and_sugg}; +use crate::utils::{is_trait_method, match_qpath, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/from_iter_instead_of_collect.rs b/clippy_lints/src/methods/from_iter_instead_of_collect.rs index 9b46adaac58..5d0a07992c8 100644 --- a/clippy_lints/src/methods/from_iter_instead_of_collect.rs +++ b/clippy_lints/src/methods/from_iter_instead_of_collect.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_trait_def_id, paths, span_lint_and_sugg, sugg}; +use crate::utils::{get_trait_def_id, paths, sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::implements_trait; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/get_unwrap.rs b/clippy_lints/src/methods/get_unwrap.rs index b9d34b402bb..ac855419d00 100644 --- a/clippy_lints/src/methods/get_unwrap.rs +++ b/clippy_lints/src/methods/get_unwrap.rs @@ -1,5 +1,6 @@ use crate::methods::derefs_to_slice; -use crate::utils::{get_parent_expr, paths, span_lint_and_sugg}; +use crate::utils::{get_parent_expr, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index a769493d11d..04461ad5c3a 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 19d05b5c693..56de7a8bc5e 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -1,5 +1,6 @@ use super::INEFFICIENT_TO_STRING; -use crate::utils::{match_def_path, paths, span_lint_and_then}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, walk_ptrs_ty_depth}; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/inspect_for_each.rs b/clippy_lints/src/methods/inspect_for_each.rs index e7c3a433fe1..c9bbfbc37eb 100644 --- a/clippy_lints/src/methods/inspect_for_each.rs +++ b/clippy_lints/src/methods/inspect_for_each.rs @@ -1,8 +1,9 @@ +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::{source_map::Span, sym}; -use crate::utils::{is_trait_method, span_lint_and_help}; +use crate::utils::is_trait_method; use super::INSPECT_FOR_EACH; diff --git a/clippy_lints/src/methods/into_iter_on_ref.rs b/clippy_lints/src/methods/into_iter_on_ref.rs index f28f082e6fc..a862b55e139 100644 --- a/clippy_lints/src/methods/into_iter_on_ref.rs +++ b/clippy_lints/src/methods/into_iter_on_ref.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_trait_method, paths, span_lint_and_sugg}; +use crate::utils::{match_trait_method, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::has_iter_method; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/iter_cloned_collect.rs b/clippy_lints/src/methods/iter_cloned_collect.rs index 1e1d3fdcf70..cd575c9cb02 100644 --- a/clippy_lints/src/methods/iter_cloned_collect.rs +++ b/clippy_lints/src/methods/iter_cloned_collect.rs @@ -1,5 +1,5 @@ use crate::methods::derefs_to_slice; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_count.rs b/clippy_lints/src/methods/iter_count.rs index 0f393423b7d..bfd62ff1f0d 100644 --- a/clippy_lints/src/methods/iter_count.rs +++ b/clippy_lints/src/methods/iter_count.rs @@ -1,5 +1,6 @@ use crate::methods::derefs_to_slice; -use crate::utils::{paths, span_lint_and_sugg}; +use crate::utils::paths; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index f79942576da..ce599682bbe 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -1,5 +1,6 @@ use crate::methods::derefs_to_slice; -use crate::utils::{get_parent_expr, higher, span_lint_and_sugg}; +use crate::utils::{get_parent_expr, higher}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/iter_nth.rs b/clippy_lints/src/methods/iter_nth.rs index 17600bb8153..2619793e1e2 100644 --- a/clippy_lints/src/methods/iter_nth.rs +++ b/clippy_lints/src/methods/iter_nth.rs @@ -1,6 +1,6 @@ use crate::methods::derefs_to_slice; use crate::methods::iter_nth_zero; -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_type_diagnostic_item; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/iter_nth_zero.rs b/clippy_lints/src/methods/iter_nth_zero.rs index 98ddfdfdf9c..f2b2dd8c097 100644 --- a/clippy_lints/src/methods/iter_nth_zero.rs +++ b/clippy_lints/src/methods/iter_nth_zero.rs @@ -1,5 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::{is_trait_method, span_lint_and_sugg}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_skip_next.rs b/clippy_lints/src/methods/iter_skip_next.rs index d191ea0a831..6100613bcac 100644 --- a/clippy_lints/src/methods/iter_skip_next.rs +++ b/clippy_lints/src/methods/iter_skip_next.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_sugg}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/iterator_step_by_zero.rs b/clippy_lints/src/methods/iterator_step_by_zero.rs index 019a08f746e..51c1ab0484e 100644 --- a/clippy_lints/src/methods/iterator_step_by_zero.rs +++ b/clippy_lints/src/methods/iterator_step_by_zero.rs @@ -1,5 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::{is_trait_method, span_lint}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index d090a35a3cf..0c8a002e359 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_qpath, span_lint_and_sugg}; +use crate::utils::match_qpath; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast; diff --git a/clippy_lints/src/methods/map_collect_result_unit.rs b/clippy_lints/src/methods/map_collect_result_unit.rs index 349b26b9d58..b59998fc8b4 100644 --- a/clippy_lints/src/methods/map_collect_result_unit.rs +++ b/clippy_lints/src/methods/map_collect_result_unit.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_sugg}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index 56719b3cff2..6f5e723fbfb 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_sugg}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/map_unwrap_or.rs b/clippy_lints/src/methods/map_unwrap_or.rs index 96dbc7ddc63..8ef02b4a641 100644 --- a/clippy_lints/src/methods/map_unwrap_or.rs +++ b/clippy_lints/src/methods/map_unwrap_or.rs @@ -1,5 +1,6 @@ +use crate::utils::meets_msrv; use crate::utils::usage::mutated_variables; -use crate::utils::{meets_msrv, span_lint, span_lint_and_sugg}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 47617e4722e..af8fe7abd96 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -52,6 +52,7 @@ mod wrong_self_convention; mod zst_offset; use bind_instead_of_map::BindInsteadOfMap; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{contains_ty, implements_trait, is_copy, is_type_diagnostic_item}; use if_chain::if_chain; @@ -69,8 +70,7 @@ use rustc_typeck::hir_ty_to_ty; use crate::utils::{ contains_return, get_trait_def_id, in_macro, iter_input_pats, match_def_path, match_qpath, method_calls, - method_chain_args, paths, return_ty, single_segment_path, span_lint, span_lint_and_help, span_lint_and_sugg, - SpanlessEq, + method_chain_args, paths, return_ty, single_segment_path, SpanlessEq, }; declare_clippy_lint! { diff --git a/clippy_lints/src/methods/ok_expect.rs b/clippy_lints/src/methods/ok_expect.rs index 2618d04b242..e6ce9cac397 100644 --- a/clippy_lints/src/methods/ok_expect.rs +++ b/clippy_lints/src/methods/ok_expect.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use if_chain::if_chain; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 6597e9f96a8..f921d7b16c0 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, meets_msrv, path_to_local_id, paths, remove_blocks, span_lint_and_sugg}; +use crate::utils::{match_def_path, meets_msrv, path_to_local_id, paths, remove_blocks}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index eed71d02467..e8b057c2d74 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_qpath, paths, span_lint_and_sugg}; +use crate::utils::{match_qpath, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 398d8f13bd4..c6459648cd5 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -1,4 +1,5 @@ -use crate::utils::{differing_macro_contexts, span_lint_and_then}; +use crate::utils::differing_macro_contexts; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_copy; use clippy_utils::ty::is_type_diagnostic_item; diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 634feebe54a..1b43802a08e 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -1,5 +1,6 @@ use crate::utils::eager_or_lazy::is_lazyness_candidate; -use crate::utils::{contains_return, get_trait_def_id, last_path_segment, paths, span_lint_and_sugg}; +use crate::utils::{contains_return, get_trait_def_id, last_path_segment, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_macro_callsite}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type}; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 6054579d988..18e1064b018 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_help, span_lint_and_sugg, strip_pat_refs}; +use crate::utils::{is_trait_method, strip_pat_refs}; +use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/single_char_insert_string.rs b/clippy_lints/src/methods/single_char_insert_string.rs index ff67564b39d..cd87d2c56b7 100644 --- a/clippy_lints/src/methods/single_char_insert_string.rs +++ b/clippy_lints/src/methods/single_char_insert_string.rs @@ -1,5 +1,5 @@ use crate::methods::get_hint_if_single_char_arg; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/single_char_pattern.rs b/clippy_lints/src/methods/single_char_pattern.rs index 61cbc9d2f0a..12d6418d700 100644 --- a/clippy_lints/src/methods/single_char_pattern.rs +++ b/clippy_lints/src/methods/single_char_pattern.rs @@ -1,5 +1,5 @@ use crate::methods::get_hint_if_single_char_arg; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/single_char_push_string.rs b/clippy_lints/src/methods/single_char_push_string.rs index 18df90c1ab3..882703a987d 100644 --- a/clippy_lints/src/methods/single_char_push_string.rs +++ b/clippy_lints/src/methods/single_char_push_string.rs @@ -1,5 +1,5 @@ use crate::methods::get_hint_if_single_char_arg; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/skip_while_next.rs b/clippy_lints/src/methods/skip_while_next.rs index a9ff78c3260..8995226191b 100644 --- a/clippy_lints/src/methods/skip_while_next.rs +++ b/clippy_lints/src/methods/skip_while_next.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, span_lint_and_help}; +use crate::utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index 1b26e8314af..d9b97168490 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -1,4 +1,5 @@ -use crate::utils::{method_chain_args, span_lint_and_sugg}; +use crate::utils::method_chain_args; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index 0ffa71de30c..fd4651dd182 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -1,5 +1,6 @@ use crate::utils::usage::mutated_variables; -use crate::utils::{expr_or_init, is_trait_method, span_lint_and_help}; +use crate::utils::{expr_or_init, is_trait_method}; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/uninit_assumed_init.rs b/clippy_lints/src/methods/uninit_assumed_init.rs index 798b66192c8..071856c3ba6 100644 --- a/clippy_lints/src/methods/uninit_assumed_init.rs +++ b/clippy_lints/src/methods/uninit_assumed_init.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, match_qpath, paths, span_lint}; +use crate::utils::{match_def_path, match_qpath, paths}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 686874c0a24..670134c68f2 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -1,5 +1,6 @@ use crate::utils::usage::mutated_variables; -use crate::utils::{is_trait_method, match_qpath, path_to_local_id, paths, span_lint}; +use crate::utils::{is_trait_method, match_qpath, path_to_local_id, paths}; +use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 4d5cbdd619d..3ccde57de3f 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_trait_method, path_to_local_id, remove_blocks, span_lint_and_sugg, strip_pat_refs}; +use crate::utils::{is_trait_method, path_to_local_id, remove_blocks, strip_pat_refs}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast; diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 444abde3d0f..3874673bf9f 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -1,5 +1,5 @@ -use crate::utils::span_lint_and_sugg; use crate::utils::{eager_or_lazy, usage}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/unwrap_used.rs b/clippy_lints/src/methods/unwrap_used.rs index efe43a6a952..2f5806115bd 100644 --- a/clippy_lints/src/methods/unwrap_used.rs +++ b/clippy_lints/src/methods/unwrap_used.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_type_diagnostic_item; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index c6d84aedc0a..13c95e33fef 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_parent_expr, match_trait_method, paths, span_lint_and_sugg}; +use crate::utils::{get_parent_expr, match_trait_method, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::walk_ptrs_ty_depth; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/wrong_self_convention.rs b/clippy_lints/src/methods/wrong_self_convention.rs index c8bcad7be3e..b728d7d8d08 100644 --- a/clippy_lints/src/methods/wrong_self_convention.rs +++ b/clippy_lints/src/methods/wrong_self_convention.rs @@ -1,5 +1,5 @@ use crate::methods::SelfKind; -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_lint::LateContext; use rustc_middle::ty::TyS; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/methods/zst_offset.rs b/clippy_lints/src/methods/zst_offset.rs index f1335726736..9f6a7c4db17 100644 --- a/clippy_lints/src/methods/zst_offset.rs +++ b/clippy_lints/src/methods/zst_offset.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 8d0c3b8e0fe..6a4e70e50af 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -1,5 +1,6 @@ use crate::consts::{constant_simple, Constant}; -use crate::utils::{match_def_path, match_trait_method, paths, span_lint}; +use crate::utils::{match_def_path, match_trait_method, paths}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index f161054cc8c..03d07287005 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::implements_trait; use if_chain::if_chain; @@ -20,8 +21,7 @@ use crate::consts::{constant, Constant}; use crate::utils::sugg::Sugg; use crate::utils::{ get_item_name, get_parent_expr, higher, in_constant, is_diagnostic_assoc_item, is_integer_const, iter_input_pats, - last_path_segment, match_qpath, span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then, unsext, - SpanlessEq, + last_path_segment, match_qpath, unsext, SpanlessEq, }; declare_clippy_lint! { diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 6ec523498e1..3c6a7071c24 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -1,4 +1,4 @@ -use crate::utils::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_opt; use rustc_ast::ast::{ BindingMode, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 4cc20b8d38c..aba4accccb1 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -1,5 +1,6 @@ use crate::utils::qualify_min_const_fn::is_min_const_fn; -use crate::utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, span_lint, trait_ref_of_method}; +use crate::utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, trait_ref_of_method}; +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::has_drop; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 6ec4c38d0f9..fd6f31faa94 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -5,7 +5,7 @@ // [`missing_doc`]: https://github.com/rust-lang/rust/blob/cf9cf7c923eb01146971429044f216a3ca905e06/compiler/rustc_lint/src/builtin.rs#L415 // -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_ast::ast::{self, MetaItem, MetaItemKind}; use rustc_ast::attr; diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index da59c820999..dd4488f3f02 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_ast::ast; use rustc_hir as hir; use rustc_lint::{self, LateContext, LateLintPass, LintContext}; diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index da3ae1d652f..1b00cf2c75d 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -1,5 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::{sext, span_lint_and_then}; +use crate::utils::sext; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index c1773cef7a8..6eaeaebe781 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -1,6 +1,7 @@ //! lint on multiple versions of a crate being used -use crate::utils::{run_lints, span_lint}; +use crate::utils::run_lints; +use clippy_utils::diagnostics::span_lint; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::{Crate, CRATE_HIR_ID}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 908b7bb7ce0..39aec79734c 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint, trait_ref_of_method}; +use crate::utils::{match_def_path, paths, trait_ref_of_method}; +use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::TypeFoldable; diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index d7239b328bb..c11ccc94890 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -1,4 +1,5 @@ -use crate::utils::{higher, span_lint}; +use crate::utils::higher; +use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; use rustc_hir::intravisit; use rustc_lint::{LateContext, LateLintPass, LintContext}; diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs index e4a57661f97..b9ba74c7d02 100644 --- a/clippy_lints/src/mut_mutex_lock.rs +++ b/clippy_lints/src/mut_mutex_lock.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 3f0b765df15..0c09ddb8073 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 9ac127abe0a..fb8895e08d0 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -1,4 +1,5 @@ -use crate::utils::{higher, is_direct_expn_of, span_lint}; +use crate::utils::{higher, is_direct_expn_of}; +use clippy_utils::diagnostics::span_lint; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 9f746ce2e1a..354e2c3fb74 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -2,7 +2,7 @@ //! //! This lint is **warn** by default -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::is_type_diagnostic_item; use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index 7687962bdd9..c62ff7323f3 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, span_lint_and_sugg}; +use crate::utils::in_macro; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_ast::ast::{BindingMode, Lifetime, Mutability, Param, PatKind, Path, TyKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 22adbdf09a6..4c67304d23e 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -3,7 +3,8 @@ //! This lint is **warn** by default use crate::utils::sugg::Sugg; -use crate::utils::{is_expn_of, parent_node_is_if_expr, span_lint, span_lint_and_sugg}; +use crate::utils::{is_expn_of, parent_node_is_if_expr}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet_with_applicability; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index d8b574af1fe..72436b51dcb 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -2,7 +2,8 @@ //! //! This lint is **warn** by default -use crate::utils::{is_automatically_derived, span_lint_and_then}; +use crate::utils::is_automatically_derived; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 5ee71f25694..7fbffe04a3f 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 4ff90704207..91c97ef7c2a 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -33,6 +33,7 @@ //! ``` //! //! This lint is **warn** by default. +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::{indent_of, snippet, snippet_block}; use rustc_ast::ast; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -40,8 +41,6 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{original_sp, DUMMY_SP}; use rustc_span::Span; -use crate::utils::span_lint_and_help; - declare_clippy_lint! { /// **What it does:** The lint checks for `if`-statements appearing in loops /// that contain a `continue` statement in either their main blocks or their diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 6f7a5d85480..fc8ee6cb8ef 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -1,5 +1,6 @@ use crate::utils::ptr::get_spans; -use crate::utils::{get_trait_def_id, is_self, multispan_sugg, paths, span_lint_and_then}; +use crate::utils::{get_trait_def_id, is_self, paths}; +use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item}; use if_chain::if_chain; diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index bcc39ff855c..ecf48d082af 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; @@ -140,7 +141,7 @@ fn emit_lint(cx: &LateContext<'_>, expr: &SomeOkCall<'_>) { SomeOkCall::OkCall(outer, inner) | SomeOkCall::SomeCall(outer, inner) => (outer, inner), }; - utils::span_lint_and_sugg( + span_lint_and_sugg( cx, NEEDLESS_QUESTION_MARK, entire_expr.span, diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 41cf541ecf5..e93de8a252a 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 67d49f06ad9..e291885d34d 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::implements_trait; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; @@ -5,7 +6,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{self, paths, span_lint}; +use crate::utils::{self, paths}; declare_clippy_lint! { /// **What it does:** diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index ef7cc65cfcf..7b00879251f 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; @@ -5,7 +6,6 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use crate::consts::{self, Constant}; -use crate::utils::span_lint; declare_clippy_lint! { /// **What it does:** Checks for multiplication by -1 as a form of negation. diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index de2899c3462..9fbb6b02742 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -1,6 +1,7 @@ use crate::utils::paths; use crate::utils::sugg::DiagnosticBuilderExt; -use crate::utils::{get_trait_def_id, return_ty, span_lint_hir_and_then}; +use crate::utils::{get_trait_def_id, return_ty}; +use clippy_utils::diagnostics::span_lint_hir_and_then; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 7a7bc7a44cd..83953a16bc8 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -1,4 +1,4 @@ -use crate::utils::{span_lint, span_lint_and_sugg}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::has_drop; use rustc_errors::Applicability; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 8aebce67917..5db614497e3 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -4,6 +4,7 @@ use std::ptr; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{ @@ -18,7 +19,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{InnerSpan, Span, DUMMY_SP}; use rustc_typeck::hir_ty_to_ty; -use crate::utils::{in_constant, span_lint_and_then}; +use crate::utils::in_constant; use if_chain::if_chain; // FIXME: this is a correctness problem but there's no suitable diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 7c74b316018..52661416de6 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -1,4 +1,4 @@ -use crate::utils::{span_lint, span_lint_and_then}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, PatKind, }; diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 71e77932f7a..8e8aaa67afa 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -1,4 +1,5 @@ -use crate::utils::{paths, span_lint}; +use crate::utils::paths; +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::match_type; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index fd653044a1b..343159f9ae2 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_direct_expn_of, span_lint_and_help}; +use crate::utils::is_direct_expn_of; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 8a6d257848f..eab08a58320 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -1,7 +1,8 @@ use crate::utils; use crate::utils::eager_or_lazy; +use crate::utils::paths; use crate::utils::sugg::Sugg; -use crate::utils::{paths, span_lint_and_sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 3c041bac234..524b96921fe 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -1,4 +1,5 @@ -use crate::utils::{span_lint, SpanlessEq}; +use crate::utils::SpanlessEq; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 1821e2611ff..880951f3e3e 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -1,4 +1,5 @@ -use crate::utils::{find_macro_calls, return_ty, span_lint_and_then}; +use crate::utils::{find_macro_calls, return_ty}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index 359620cc079..ad4ed831941 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_expn_of, match_panic_call, span_lint}; +use crate::utils::{is_expn_of, match_panic_call}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index aca1ed5ca65..06985cef4ff 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_automatically_derived, span_lint_hir}; +use crate::utils::is_automatically_derived; +use clippy_utils::diagnostics::span_lint_hir; use if_chain::if_chain; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 757ead2c24c..c14273840c4 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -1,6 +1,7 @@ use std::cmp; -use crate::utils::{is_self_ty, span_lint_and_sugg}; +use crate::utils::is_self_ty; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_copy; use if_chain::if_chain; diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 46533682d42..95ffae28d8c 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_ast::ast::LitKind; diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 5539331d046..dd63cf99e42 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -1,4 +1,5 @@ -use crate::utils::{last_path_segment, span_lint_and_help}; +use crate::utils::last_path_segment; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{ intravisit, Body, Expr, ExprKind, FieldPat, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatKind, QPath, Stmt, StmtKind, diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index fbe54e92ab9..9cf00c953b9 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast::{BinOpKind, Expr, ExprKind, LitKind, UnOp}; diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index bfe8bf33f51..779eddcc170 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -1,7 +1,8 @@ //! Checks for usage of `&Vec[_]` and `&String`. use crate::utils::ptr::get_spans; -use crate::utils::{is_allowed, match_qpath, paths, span_lint, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::{is_allowed, match_qpath, paths}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{is_type_diagnostic_item, match_type, walk_ptrs_hir_ty}; use if_chain::if_chain; diff --git a/clippy_lints/src/ptr_eq.rs b/clippy_lints/src/ptr_eq.rs index 4f83e370c5f..82408c639b1 100644 --- a/clippy_lints/src/ptr_eq.rs +++ b/clippy_lints/src/ptr_eq.rs @@ -1,4 +1,5 @@ use crate::utils; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_errors::Applicability; @@ -58,7 +59,7 @@ impl LateLintPass<'_> for PtrEq { if let Some(left_snip) = snippet_opt(cx, left_var.span); if let Some(right_snip) = snippet_opt(cx, right_var.span); then { - utils::span_lint_and_sugg( + span_lint_and_sugg( cx, PTR_EQ, expr.span, diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index b801defeb24..c04b4255256 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -1,4 +1,4 @@ -use crate::utils::{span_lint, span_lint_and_sugg}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet_opt; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 43431425a43..c4686623487 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -9,7 +9,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; use crate::utils::sugg::Sugg; -use crate::utils::{eq_expr_value, match_def_path, match_qpath, paths, span_lint_and_sugg}; +use crate::utils::{eq_expr_value, match_def_path, match_qpath, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; declare_clippy_lint! { /// **What it does:** Checks for expressions that could be replaced by the question mark operator. diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 3ce8949bf8b..d476d95256f 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -1,4 +1,5 @@ use crate::consts::{constant, Constant}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability}; use if_chain::if_chain; use rustc_ast::ast::RangeLimits; @@ -14,10 +15,7 @@ use rustc_span::symbol::Ident; use std::cmp::Ordering; use crate::utils::sugg::Sugg; -use crate::utils::{ - get_parent_expr, in_constant, is_integer_const, meets_msrv, single_segment_path, span_lint, span_lint_and_sugg, - span_lint_and_then, -}; +use crate::utils::{get_parent_expr, in_constant, is_integer_const, meets_msrv, single_segment_path}; use crate::utils::{higher, SpanlessEq}; declare_clippy_lint! { diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 84723acd034..3d799328bb5 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -1,4 +1,5 @@ -use crate::utils::{fn_has_unsatisfiable_preds, match_def_path, paths, span_lint_hir, span_lint_hir_and_then}; +use crate::utils::{fn_has_unsatisfiable_preds, match_def_path, paths}; +use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, walk_ptrs_ty_depth}; use if_chain::if_chain; diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 283e25553cf..2977a108d14 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -1,4 +1,4 @@ -use crate::utils::{span_lint, span_lint_and_then}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast; diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 3d585cd27a3..061526c6f09 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_ast::visit::{walk_expr, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 38dcf7a192c..fd11150bce2 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -1,4 +1,5 @@ -use crate::utils::{meets_msrv, span_lint_and_sugg}; +use crate::utils::meets_msrv; +use clippy_utils::diagnostics::span_lint_and_sugg; use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index c876bae2303..e091095de13 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind, VisibilityKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 85ea91a387b..6da7b5fbcc8 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_lang_item; use if_chain::if_chain; @@ -7,8 +8,6 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::{lint::in_external_macro, ty::TyS}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::span_lint_and_sugg; - declare_clippy_lint! { /// **What it does:** Checks for redundant slicing expressions which use the full range, and /// do not change the type. diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 1352a651723..da8339a795a 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -1,4 +1,5 @@ -use crate::utils::{meets_msrv, span_lint_and_then}; +use crate::utils::meets_msrv; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use rustc_ast::ast::{Item, ItemKind, Ty, TyKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index cec6b06262b..452fef0694f 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -1,4 +1,5 @@ -use crate::utils::{last_path_segment, span_lint_and_sugg}; +use crate::utils::last_path_segment; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index 31e834ac174..ec2acb6a0ab 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -1,5 +1,6 @@ +use crate::utils::in_macro; use crate::utils::sugg::Sugg; -use crate::utils::{in_macro, span_lint_and_sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp}; diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 1edea613148..bfa21ba9c97 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -1,5 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::{match_def_path, paths, span_lint, span_lint_and_help}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use if_chain::if_chain; use rustc_ast::ast::{LitKind, StrStyle}; use rustc_data_structures::fx::FxHashSet; diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs index a88078c12a3..b39e9d5a78c 100644 --- a/clippy_lints/src/repeat_once.rs +++ b/clippy_lints/src/repeat_once.rs @@ -1,5 +1,6 @@ use crate::consts::{constant_context, Constant}; -use crate::utils::{in_macro, span_lint_and_sugg}; +use crate::utils::in_macro; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index eb7fe403fd7..59d3c0ca5f0 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::Attribute; @@ -12,7 +13,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::sym; -use crate::utils::{fn_def_id, in_macro, match_qpath, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::{fn_def_id, in_macro, match_qpath}; declare_clippy_lint! { /// **What it does:** Checks for `let`-bindings, which are subsequently diff --git a/clippy_lints/src/self_assignment.rs b/clippy_lints/src/self_assignment.rs index e62b75de4ca..320d1a8dbe3 100644 --- a/clippy_lints/src/self_assignment.rs +++ b/clippy_lints/src/self_assignment.rs @@ -1,4 +1,5 @@ -use crate::utils::{eq_expr_value, span_lint}; +use crate::utils::eq_expr_value; +use clippy_utils::diagnostics::span_lint; use clippy_utils::source::snippet; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index 695d7233af2..e43947025b9 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, span_lint_and_sugg, sugg}; +use crate::utils::{in_macro, sugg}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_macro_callsite; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 90cf1b6c861..632715852c5 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_trait_def_id, paths, span_lint}; +use crate::utils::{get_trait_def_id, paths}; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 4a8cacb31fd..8ef58b6d563 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -1,4 +1,5 @@ -use crate::utils::{contains_name, higher, iter_input_pats, span_lint_and_then}; +use crate::utils::{contains_name, higher, iter_input_pats}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use rustc_hir::intravisit::FnKind; use rustc_hir::{ diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 1fc4ff5c2e6..6d15a6c444e 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, span_lint_and_sugg}; +use crate::utils::in_macro; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use rustc_ast::{Item, ItemKind, UseTreeKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index 87e386baadc..8920d446b9c 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -1,7 +1,8 @@ //! Lint on use of `size_of` or `size_of_val` of T in an expression //! expecting a count of T -use crate::utils::{match_def_path, paths, span_lint_and_help}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::BinOpKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 96f6881556c..7f0f21084af 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -1,5 +1,6 @@ use crate::utils::sugg::Sugg; -use crate::utils::{get_enclosing_block, match_qpath, span_lint_and_then, SpanlessEq}; +use crate::utils::{get_enclosing_block, match_qpath, SpanlessEq}; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 276a9338819..85e4bb806e7 100644 --- a/clippy_lints/src/stable_sort_primitive.rs +++ b/clippy_lints/src/stable_sort_primitive.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_slice_of_primitives, span_lint_and_then, sugg::Sugg}; +use crate::utils::{is_slice_of_primitives, sugg::Sugg}; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index ce93ab23b2f..626166f9008 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -1,8 +1,6 @@ use crate::utils::SpanlessEq; -use crate::utils::{ - get_parent_expr, is_allowed, match_function_call, method_calls, paths, span_lint, span_lint_and_help, - span_lint_and_sugg, -}; +use crate::utils::{get_parent_expr, is_allowed, match_function_call, method_calls, paths}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 3bdd9b7e4cb..364c99adc69 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -1,5 +1,5 @@ use crate::utils::ast_utils::{eq_id, is_useless_with_eq_exprs, IdentIter}; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use core::ops::{Add, AddAssign}; use if_chain::if_chain; diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 0b7d08cb164..ef14b6c5136 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_trait_def_id, span_lint, trait_ref_of_method}; +use crate::utils::{get_trait_def_id, trait_ref_of_method}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir as hir; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index d4a495f3ea9..83fe3c49959 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -1,5 +1,6 @@ use crate::utils::sugg::Sugg; -use crate::utils::{differing_macro_contexts, eq_expr_value, span_lint_and_then}; +use crate::utils::{differing_macro_contexts, eq_expr_value}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index 74ccd9235de..88bd2feaadd 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use rustc_ast::ast; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index fb891866364..75a13cb9187 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_adjusted, span_lint}; +use crate::utils::is_adjusted; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 940273afc57..abc9b2fe88e 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, span_lint_and_sugg}; +use crate::utils::match_def_path; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index 84ec2aa18ab..42605c01089 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_diagnostic_assoc_item, match_def_path, path_to_local_id, paths, span_lint}; +use crate::utils::{is_diagnostic_assoc_item, match_def_path, path_to_local_id, paths}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index d3314271c21..cfcc8da9910 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, span_lint_and_help, SpanlessHash}; +use crate::utils::{in_macro, SpanlessHash}; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::{snippet, snippet_with_applicability}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashMap; diff --git a/clippy_lints/src/transmute/crosspointer_transmute.rs b/clippy_lints/src/transmute/crosspointer_transmute.rs index ce87defaa94..25d0543c861 100644 --- a/clippy_lints/src/transmute/crosspointer_transmute.rs +++ b/clippy_lints/src/transmute/crosspointer_transmute.rs @@ -1,5 +1,5 @@ use super::CROSSPOINTER_TRANSMUTE; -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; diff --git a/clippy_lints/src/transmute/transmute_float_to_int.rs b/clippy_lints/src/transmute/transmute_float_to_int.rs index 562d880e39a..f61b5362b5a 100644 --- a/clippy_lints/src/transmute/transmute_float_to_int.rs +++ b/clippy_lints/src/transmute/transmute_float_to_int.rs @@ -1,5 +1,6 @@ use super::TRANSMUTE_FLOAT_TO_INT; -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_ast as ast; use rustc_errors::Applicability; diff --git a/clippy_lints/src/transmute/transmute_int_to_bool.rs b/clippy_lints/src/transmute/transmute_int_to_bool.rs index 5b609f906a3..ebdd1eba744 100644 --- a/clippy_lints/src/transmute/transmute_int_to_bool.rs +++ b/clippy_lints/src/transmute/transmute_int_to_bool.rs @@ -1,5 +1,6 @@ use super::TRANSMUTE_INT_TO_BOOL; -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast as ast; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/transmute/transmute_int_to_char.rs b/clippy_lints/src/transmute/transmute_int_to_char.rs index 29d2450618a..afecfc3d701 100644 --- a/clippy_lints/src/transmute/transmute_int_to_char.rs +++ b/clippy_lints/src/transmute/transmute_int_to_char.rs @@ -1,5 +1,6 @@ use super::TRANSMUTE_INT_TO_CHAR; -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast as ast; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/transmute/transmute_int_to_float.rs b/clippy_lints/src/transmute/transmute_int_to_float.rs index f83fba8966a..c762a7ab885 100644 --- a/clippy_lints/src/transmute/transmute_int_to_float.rs +++ b/clippy_lints/src/transmute/transmute_int_to_float.rs @@ -1,5 +1,6 @@ use super::TRANSMUTE_INT_TO_FLOAT; -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index f4e60a3020c..820c56a215e 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -1,5 +1,6 @@ use super::TRANSMUTE_PTR_TO_PTR; -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index f5dbbbe33bc..049210e555c 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -1,6 +1,7 @@ use super::utils::get_type_snippet; use super::TRANSMUTE_PTR_TO_REF; -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability, QPath}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index 4780eb9b14e..993ef8698f8 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -1,5 +1,6 @@ use super::{TRANSMUTE_BYTES_TO_STR, TRANSMUTE_PTR_TO_PTR}; -use crate::utils::{span_lint_and_sugg, span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs index dea896622f1..da7d1016d97 100644 --- a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs +++ b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs @@ -1,6 +1,7 @@ use super::utils::can_be_expressed_as_pointer_cast; use super::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS; -use crate::utils::{span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/unsound_collection_transmute.rs b/clippy_lints/src/transmute/unsound_collection_transmute.rs index 503c5e0ff38..9bea88be7da 100644 --- a/clippy_lints/src/transmute/unsound_collection_transmute.rs +++ b/clippy_lints/src/transmute/unsound_collection_transmute.rs @@ -1,6 +1,7 @@ use super::utils::is_layout_incompatible; use super::UNSOUND_COLLECTION_TRANSMUTE; -use crate::utils::{match_def_path, paths, span_lint}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::span_lint; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 83441514af0..29ffe03b673 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -1,5 +1,6 @@ use super::USELESS_TRANSMUTE; -use crate::utils::{span_lint, span_lint_and_then, sugg}; +use crate::utils::sugg; +use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/wrong_transmute.rs b/clippy_lints/src/transmute/wrong_transmute.rs index d6d77f2c834..2118f3d6950 100644 --- a/clippy_lints/src/transmute/wrong_transmute.rs +++ b/clippy_lints/src/transmute/wrong_transmute.rs @@ -1,5 +1,5 @@ use super::WRONG_TRANSMUTE; -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 2ba2b646f00..3a2b1359a54 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -1,5 +1,6 @@ use crate::consts::{constant_context, Constant}; -use crate::utils::{match_qpath, paths, span_lint}; +use crate::utils::{match_qpath, paths}; +use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_ast::LitKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index e356add8e9d..1fce03b4f47 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -1,4 +1,5 @@ -use crate::utils::{differing_macro_contexts, in_macro, match_def_path, match_qpath, paths, span_lint_and_sugg}; +use crate::utils::{differing_macro_contexts, in_macro, match_def_path, match_qpath, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet, snippet_with_macro_callsite}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 01aeea7a67f..eab81b1e246 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_path, paths, span_lint_and_sugg}; +use crate::utils::{match_path, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/types/box_vec.rs b/clippy_lints/src/types/box_vec.rs index 6aa98e435e1..6d04a47a5c8 100644 --- a/clippy_lints/src/types/box_vec.rs +++ b/clippy_lints/src/types/box_vec.rs @@ -1,8 +1,9 @@ +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{self as hir, def_id::DefId, QPath}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::{is_ty_param_diagnostic_item, span_lint_and_help}; +use crate::utils::is_ty_param_diagnostic_item; use super::BOX_VEC; diff --git a/clippy_lints/src/types/linked_list.rs b/clippy_lints/src/types/linked_list.rs index 47eb4ede4e4..e9e1995f6a5 100644 --- a/clippy_lints/src/types/linked_list.rs +++ b/clippy_lints/src/types/linked_list.rs @@ -1,7 +1,8 @@ +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{self as hir, def_id::DefId}; use rustc_lint::LateContext; -use crate::utils::{match_def_path, paths, span_lint_and_help}; +use crate::utils::{match_def_path, paths}; use super::LINKEDLIST; diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 279a971318c..ac4fe502a7a 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -13,6 +13,7 @@ use std::borrow::Cow; use std::cmp::Ordering; use std::collections::BTreeMap; +use clippy_utils::diagnostics::{multispan_sugg, span_lint, span_lint_and_help, span_lint_and_then}; use clippy_utils::source::{indent_of, reindent_multiline, snippet, snippet_opt, snippet_with_macro_callsite}; use clippy_utils::ty::{is_isize_or_usize, is_type_diagnostic_item}; use if_chain::if_chain; @@ -38,10 +39,7 @@ use rustc_typeck::hir_ty_to_ty; use crate::consts::{constant, Constant}; use crate::utils::paths; -use crate::utils::{ - clip, comparisons, differing_macro_contexts, higher, int_bits, match_path, multispan_sugg, sext, span_lint, - span_lint_and_help, span_lint_and_then, unsext, -}; +use crate::utils::{clip, comparisons, differing_macro_contexts, higher, int_bits, match_path, sext, unsext}; declare_clippy_lint! { /// **What it does:** Checks for use of `Box>` anywhere in the code. diff --git a/clippy_lints/src/types/option_option.rs b/clippy_lints/src/types/option_option.rs index dc5db963b4e..79c5a32de2c 100644 --- a/clippy_lints/src/types/option_option.rs +++ b/clippy_lints/src/types/option_option.rs @@ -1,8 +1,9 @@ +use clippy_utils::diagnostics::span_lint; use rustc_hir::{self as hir, def_id::DefId, QPath}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::{is_ty_param_diagnostic_item, span_lint}; +use crate::utils::is_ty_param_diagnostic_item; use super::OPTION_OPTION; diff --git a/clippy_lints/src/types/rc_buffer.rs b/clippy_lints/src/types/rc_buffer.rs index 0ace1807535..d5fc23f2e39 100644 --- a/clippy_lints/src/types/rc_buffer.rs +++ b/clippy_lints/src/types/rc_buffer.rs @@ -1,10 +1,11 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item, span_lint_and_sugg}; +use crate::utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item}; use super::RC_BUFFER; diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index c6f6a2f6564..71c014f96f7 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -1,10 +1,11 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, LangItem, QPath, TyKind}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item, is_ty_param_lang_item, span_lint_and_sugg}; +use crate::utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item, is_ty_param_lang_item}; use super::{utils, REDUNDANT_ALLOCATION}; diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index 6f45442b9ba..8cedb0ede2b 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; @@ -8,7 +9,7 @@ use rustc_span::symbol::sym; use rustc_target::abi::LayoutOf; use rustc_typeck::hir_ty_to_ty; -use crate::utils::{last_path_segment, span_lint_and_sugg}; +use crate::utils::last_path_segment; use super::VEC_BOX; diff --git a/clippy_lints/src/undropped_manually_drops.rs b/clippy_lints/src/undropped_manually_drops.rs index 8c34ca16e6f..943573a2b53 100644 --- a/clippy_lints/src/undropped_manually_drops.rs +++ b/clippy_lints/src/undropped_manually_drops.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_function_call, paths, span_lint_and_help}; +use crate::utils::{match_function_call, paths}; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_type_lang_item; use rustc_hir::{lang_items, Expr}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index e44fec7ad8e..c37bbf297f8 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_allowed, span_lint_and_sugg}; +use crate::utils::is_allowed; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index c6ae8b9b598..d0456347f8a 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -1,4 +1,5 @@ -use crate::utils::{get_trait_def_id, paths, span_lint, span_lint_and_help}; +use crate::utils::{get_trait_def_id, paths}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, StmtKind}; diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 9582c162e77..2c51a8556d9 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, paths, span_lint, span_lint_and_help}; +use crate::utils::{match_def_path, paths}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 7e385b00646..aa83f6a74be 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -1,5 +1,5 @@ -use crate::utils; use crate::utils::sugg::Sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; @@ -233,7 +233,7 @@ fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { impl LateLintPass<'_> for UnnecessarySortBy { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { match detect_lint(cx, expr) { - Some(LintTrigger::SortByKey(trigger)) => utils::span_lint_and_sugg( + Some(LintTrigger::SortByKey(trigger)) => span_lint_and_sugg( cx, UNNECESSARY_SORT_BY, expr.span, @@ -256,7 +256,7 @@ impl LateLintPass<'_> for UnnecessarySortBy { Applicability::MachineApplicable }, ), - Some(LintTrigger::Sort(trigger)) => utils::span_lint_and_sugg( + Some(LintTrigger::Sort(trigger)) => span_lint_and_sugg( cx, UNNECESSARY_SORT_BY, expr.span, diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 01497de3211..cb20192b683 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -1,6 +1,5 @@ -use crate::utils::{ - contains_return, in_macro, match_qpath, paths, return_ty, span_lint_and_then, visitors::find_all_ret_expressions, -}; +use crate::utils::{contains_return, in_macro, match_qpath, paths, return_ty, visitors::find_all_ret_expressions}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 7f4f16f8faf..42ff1809ff4 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -1,7 +1,8 @@ #![allow(clippy::wildcard_imports, clippy::enum_glob_use)] use crate::utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path}; -use crate::utils::{over, span_lint_and_then}; +use crate::utils::over; +use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::mut_visit::*; use rustc_ast::ptr::P; use rustc_ast::{self as ast, Pat, PatKind, PatKind::*, DUMMY_NODE_ID}; diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 154082a0fdb..16ad9d2dfd3 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint; +use clippy_utils::diagnostics::span_lint; use rustc_ast::ast::{Item, ItemKind, UseTree, UseTreeKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 43166d26787..31fd61f99f2 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -1,4 +1,5 @@ -use crate::utils::{is_try, match_trait_method, paths, span_lint}; +use crate::utils::{is_try, match_trait_method, paths}; +use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 812482cf5cf..4642bf07c45 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -1,9 +1,9 @@ +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::{Impl, ImplItem, ImplItemKind, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::span_lint_and_help; use crate::utils::visitors::LocalUsedVisitor; declare_clippy_lint! { diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index a90d26fc95c..c45b851211c 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -8,7 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::BytePos; -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; declare_clippy_lint! { /// **What it does:** Checks for unit (`()`) expressions that can be removed. diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 43b5f138a42..75b2f2da602 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -1,4 +1,5 @@ -use crate::utils::{differing_macro_contexts, span_lint_and_then, usage::is_potentially_mutated}; +use crate::utils::{differing_macro_contexts, usage::is_potentially_mutated}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 6a8f8211566..a85f3ce5c9c 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -1,4 +1,5 @@ -use crate::utils::{method_chain_args, return_ty, span_lint_and_then}; +use crate::utils::{method_chain_args, return_ty}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_hir as hir; diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 0470e1dbbb8..7ce9aa13184 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; use itertools::Itertools; use rustc_ast::ast::{Item, ItemKind, Variant}; @@ -81,7 +81,7 @@ fn check_ident(cx: &EarlyContext<'_>, ident: &Ident, be_aggressive: bool) { // assume that two-letter words are some kind of valid abbreviation like FP for false positive // (and don't warn) if (ident.chars().all(|c| c.is_ascii_uppercase()) && ident.len() > 2) - // otherwise, warn if we have SOmeTHING lIKE THIs but only warn with the aggressive + // otherwise, warn if we have SOmeTHING lIKE THIs but only warn with the aggressive // upper-case-acronyms-aggressive config option enabled || (be_aggressive && ident != &corrected) { diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index de7eb42d56d..9a42c833470 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -1,7 +1,7 @@ +use crate::utils::{in_macro, meets_msrv}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use if_chain::if_chain; - -use crate::utils::{in_macro, meets_msrv, span_lint_and_sugg}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::DefKind; diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index e6b4fde560f..1eb152daac8 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -1,7 +1,6 @@ use crate::utils::sugg::Sugg; -use crate::utils::{ - get_parent_expr, match_def_path, match_trait_method, paths, span_lint_and_help, span_lint_and_sugg, -}; +use crate::utils::{get_parent_expr, match_def_path, match_trait_method, paths}; +use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_macro_callsite}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 04b8d9ee2c7..a566362ae78 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,8 +1,7 @@ use crate::consts::{constant_simple, Constant}; -use crate::utils::{ - is_expn_of, match_def_path, match_qpath, method_calls, path_to_res, paths, run_lints, span_lint, - span_lint_and_help, span_lint_and_sugg, SpanlessEq, -}; +use crate::utils::{is_expn_of, match_def_path, match_qpath, method_calls, path_to_res, paths, run_lints, SpanlessEq}; + +use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::snippet; use clippy_utils::ty::match_type; use if_chain::if_chain; diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index cd09a5b53e0..9e142413365 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -1,6 +1,7 @@ use crate::consts::{constant, Constant}; use crate::rustc_target::abi::LayoutOf; -use crate::utils::{higher, span_lint_and_sugg}; +use crate::utils::higher; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_copy; use if_chain::if_chain; diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 4ad787ecf66..3ef55a82a17 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -1,4 +1,5 @@ -use crate::utils::{match_def_path, path_to_local, path_to_local_id, paths, span_lint_and_sugg}; +use crate::utils::{match_def_path, path_to_local, path_to_local_id, paths}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index d2494b321ef..9a2fb1414a1 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index 079a4279c60..01dc54dc5fd 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -1,4 +1,5 @@ -use crate::utils::{paths, span_lint_and_help}; +use crate::utils::paths; +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::match_type; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, QPath}; diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index cd1864f461d..8f96b962279 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,4 +1,5 @@ -use crate::utils::{run_lints, span_lint}; +use crate::utils::run_lints; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index e12ca49fd4c..424ca2a4c2f 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -1,4 +1,5 @@ -use crate::utils::{in_macro, span_lint_and_sugg}; +use crate::utils::in_macro; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet, snippet_with_applicability}; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index f2fef73a641..fd3e5a7ce91 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::ops::Range; -use crate::utils::{span_lint, span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind, ImplKind, Item, ItemKind, LitKind, MacCall, StrLit, StrStyle}; diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 11d96e15ff1..3b4890ad560 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -1,5 +1,5 @@ use crate::consts::{constant_simple, Constant}; -use crate::utils::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index ab27b60cfa4..82466da6862 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item, match_type}; use if_chain::if_chain; use rustc_hir::{self as hir, HirId, ItemKind, Node}; @@ -8,7 +9,7 @@ use rustc_span::sym; use rustc_target::abi::LayoutOf as _; use rustc_typeck::hir_ty_to_ty; -use crate::utils::{paths, span_lint_and_help}; +use crate::utils::paths; declare_clippy_lint! { /// **What it does:** Checks for maps with zero-sized value types anywhere in the code. diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index d895d798b5e..d3cf2a34709 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -33,7 +33,7 @@ pub mod attrs; pub mod camel_case; pub mod comparisons; pub mod consts; -mod diagnostics; +pub mod diagnostics; pub mod eager_or_lazy; pub mod higher; mod hir_utils; @@ -48,7 +48,6 @@ pub mod usage; pub mod visitors; pub use self::attrs::*; -pub use self::diagnostics::*; pub use self::hir_utils::{both, eq_expr_value, over, SpanlessEq, SpanlessHash}; use std::collections::hash_map::Entry; -- cgit 1.4.1-3-g733a5 From 0743e841f07b7c41f65187fbf71f90bb5dc71982 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 16 Mar 2021 11:06:34 -0500 Subject: Don't re-export clippy_utils::* --- clippy_lints/src/assertions_on_constants.rs | 2 +- clippy_lints/src/assign_ops.rs | 6 +++--- clippy_lints/src/atomic_ordering.rs | 2 +- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/await_holding_invalid.rs | 2 +- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/blocks_in_if_conditions.rs | 2 +- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/bytecount.rs | 2 +- clippy_lints/src/cargo_common_metadata.rs | 2 +- clippy_lints/src/casts/cast_lossless.rs | 3 +-- clippy_lints/src/casts/cast_possible_truncation.rs | 3 +-- clippy_lints/src/casts/cast_ptr_alignment.rs | 6 ++---- clippy_lints/src/casts/cast_sign_loss.rs | 10 ++++------ clippy_lints/src/casts/mod.rs | 3 +-- clippy_lints/src/casts/ptr_as_ptr.rs | 10 ++++------ clippy_lints/src/casts/unnecessary_cast.rs | 3 +-- clippy_lints/src/checked_conversions.rs | 3 +-- clippy_lints/src/cognitive_complexity.rs | 3 +-- clippy_lints/src/collapsible_if.rs | 3 +-- clippy_lints/src/collapsible_match.rs | 4 ++-- clippy_lints/src/comparison_chain.rs | 2 +- clippy_lints/src/copies.rs | 4 ++-- clippy_lints/src/create_dir.rs | 2 +- clippy_lints/src/default.rs | 2 +- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/disallowed_method.rs | 2 +- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/double_comparison.rs | 3 +-- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/duration_subsec.rs | 2 +- clippy_lints/src/entry.rs | 4 ++-- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/eq_op.rs | 2 +- clippy_lints/src/eta_reduction.rs | 3 +-- clippy_lints/src/eval_order_dependence.rs | 2 +- clippy_lints/src/excessive_bools.rs | 2 +- clippy_lints/src/exit.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 2 +- clippy_lints/src/float_equality_without_abs.rs | 2 +- clippy_lints/src/float_literal.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 2 +- clippy_lints/src/format.rs | 4 ++-- clippy_lints/src/formatting.rs | 2 +- clippy_lints/src/from_over_into.rs | 4 ++-- clippy_lints/src/from_str_radix_10.rs | 3 +-- clippy_lints/src/functions.rs | 8 ++++---- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_lints/src/get_last_with_len.rs | 2 +- clippy_lints/src/identity_op.rs | 2 +- clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/if_let_some_result.rs | 2 +- clippy_lints/src/if_then_some_else_none.rs | 10 +++++----- clippy_lints/src/implicit_return.rs | 2 +- clippy_lints/src/implicit_saturating_sub.rs | 2 +- clippy_lints/src/indexing_slicing.rs | 2 +- clippy_lints/src/infinite_iter.rs | 3 +-- clippy_lints/src/inherent_impl.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 3 +-- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/let_underscore.rs | 3 +-- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/literal_representation.rs | 6 +++--- clippy_lints/src/loops/empty_loop.rs | 2 +- clippy_lints/src/loops/explicit_counter_loop.rs | 2 +- clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_lints/src/loops/for_kv_map.rs | 4 ++-- clippy_lints/src/loops/iter_next_loop.rs | 3 +-- clippy_lints/src/loops/manual_flatten.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 4 ++-- clippy_lints/src/loops/mod.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/loops/needless_collect.rs | 4 ++-- clippy_lints/src/loops/needless_range_loop.rs | 8 ++++---- clippy_lints/src/loops/single_element_loop.rs | 2 +- clippy_lints/src/loops/utils.rs | 2 +- clippy_lints/src/loops/while_immutable_condition.rs | 2 +- clippy_lints/src/loops/while_let_on_iterator.rs | 8 ++++---- clippy_lints/src/macro_use.rs | 2 +- clippy_lints/src/main_recursion.rs | 3 +-- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/manual_map.rs | 7 ++----- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/manual_ok_or.rs | 2 +- clippy_lints/src/manual_strip.rs | 4 ++-- clippy_lints/src/manual_unwrap_or.rs | 14 +++++++------- clippy_lints/src/map_clone.rs | 4 ++-- clippy_lints/src/map_identity.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/matches.rs | 16 ++++++++-------- clippy_lints/src/mem_discriminant.rs | 2 +- clippy_lints/src/mem_forget.rs | 2 +- clippy_lints/src/mem_replace.rs | 2 +- clippy_lints/src/methods/bind_instead_of_map.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 2 +- clippy_lints/src/methods/clone_on_ref_ptr.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 2 +- clippy_lints/src/methods/filetype_is_file.rs | 2 +- clippy_lints/src/methods/filter_flat_map.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 2 +- clippy_lints/src/methods/filter_map_flat_map.rs | 2 +- clippy_lints/src/methods/filter_map_identity.rs | 2 +- clippy_lints/src/methods/filter_map_map.rs | 2 +- clippy_lints/src/methods/filter_map_next.rs | 2 +- clippy_lints/src/methods/filter_next.rs | 2 +- clippy_lints/src/methods/flat_map_identity.rs | 2 +- .../src/methods/from_iter_instead_of_collect.rs | 2 +- clippy_lints/src/methods/get_unwrap.rs | 2 +- clippy_lints/src/methods/inefficient_to_string.rs | 2 +- clippy_lints/src/methods/inspect_for_each.rs | 3 +-- clippy_lints/src/methods/into_iter_on_ref.rs | 2 +- clippy_lints/src/methods/iter_count.rs | 2 +- clippy_lints/src/methods/iter_next_slice.rs | 2 +- clippy_lints/src/methods/iter_nth_zero.rs | 2 +- clippy_lints/src/methods/iter_skip_next.rs | 2 +- clippy_lints/src/methods/iterator_step_by_zero.rs | 2 +- .../src/methods/manual_saturating_arithmetic.rs | 2 +- clippy_lints/src/methods/map_collect_result_unit.rs | 2 +- clippy_lints/src/methods/map_flatten.rs | 2 +- clippy_lints/src/methods/map_unwrap_or.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 9 ++++----- clippy_lints/src/methods/option_as_ref_deref.rs | 2 +- clippy_lints/src/methods/option_map_or_none.rs | 2 +- clippy_lints/src/methods/option_map_unwrap_or.rs | 2 +- clippy_lints/src/methods/or_fun_call.rs | 4 ++-- clippy_lints/src/methods/search_is_some.rs | 2 +- clippy_lints/src/methods/skip_while_next.rs | 2 +- clippy_lints/src/methods/string_extend_chars.rs | 2 +- clippy_lints/src/methods/suspicious_map.rs | 4 ++-- clippy_lints/src/methods/uninit_assumed_init.rs | 2 +- clippy_lints/src/methods/unnecessary_filter_map.rs | 7 +++---- clippy_lints/src/methods/unnecessary_fold.rs | 2 +- clippy_lints/src/methods/unnecessary_lazy_eval.rs | 2 +- clippy_lints/src/methods/useless_asref.rs | 2 +- clippy_lints/src/minmax.rs | 2 +- clippy_lints/src/misc.rs | 4 ++-- clippy_lints/src/missing_const_for_fn.rs | 4 ++-- clippy_lints/src/modulo_arithmetic.rs | 2 +- clippy_lints/src/multiple_crate_versions.rs | 2 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/mut_mut.rs | 2 +- clippy_lints/src/mutable_debug_assertion.rs | 2 +- clippy_lints/src/needless_arbitrary_self_type.rs | 2 +- clippy_lints/src/needless_bool.rs | 4 ++-- clippy_lints/src/needless_borrow.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/needless_question_mark.rs | 11 +++++------ clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 5 ++--- clippy_lints/src/new_without_default.rs | 6 +++--- clippy_lints/src/non_copy_const.rs | 5 ++--- clippy_lints/src/open_options.rs | 2 +- clippy_lints/src/option_env_unwrap.rs | 2 +- clippy_lints/src/option_if_let_else.rs | 19 +++++++++---------- clippy_lints/src/overflow_check_conditional.rs | 2 +- clippy_lints/src/panic_in_result_fn.rs | 2 +- clippy_lints/src/panic_unimplemented.rs | 2 +- clippy_lints/src/partialeq_ne_impl.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/ptr_eq.rs | 4 ++-- clippy_lints/src/question_mark.rs | 7 +++---- clippy_lints/src/ranges.rs | 7 +++---- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/redundant_field_names.rs | 2 +- clippy_lints/src/redundant_static_lifetimes.rs | 2 +- clippy_lints/src/ref_option_ref.rs | 2 +- clippy_lints/src/reference.rs | 4 ++-- clippy_lints/src/regex.rs | 2 +- clippy_lints/src/repeat_once.rs | 2 +- clippy_lints/src/returns.rs | 3 +-- clippy_lints/src/self_assignment.rs | 2 +- clippy_lints/src/semicolon_if_nothing_returned.rs | 2 +- clippy_lints/src/serde_api.rs | 2 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/single_component_path_imports.rs | 2 +- clippy_lints/src/size_of_in_element_count.rs | 2 +- clippy_lints/src/slow_vector_initialization.rs | 4 ++-- clippy_lints/src/stable_sort_primitive.rs | 4 +--- clippy_lints/src/strings.rs | 4 ++-- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 4 ++-- clippy_lints/src/swap.rs | 4 ++-- clippy_lints/src/temporary_assignment.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 2 +- clippy_lints/src/to_string_in_display.rs | 2 +- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/transmute/mod.rs | 2 +- clippy_lints/src/transmute/transmute_float_to_int.rs | 2 +- clippy_lints/src/transmute/transmute_int_to_bool.rs | 2 +- clippy_lints/src/transmute/transmute_int_to_char.rs | 2 +- clippy_lints/src/transmute/transmute_int_to_float.rs | 2 +- clippy_lints/src/transmute/transmute_ptr_to_ptr.rs | 2 +- clippy_lints/src/transmute/transmute_ptr_to_ref.rs | 2 +- clippy_lints/src/transmute/transmute_ref_to_ref.rs | 2 +- .../transmute/transmutes_expressible_as_ptr_casts.rs | 2 +- .../src/transmute/unsound_collection_transmute.rs | 2 +- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_lints/src/transmute/utils.rs | 2 +- clippy_lints/src/transmuting_null.rs | 2 +- clippy_lints/src/try_err.rs | 2 +- clippy_lints/src/types/borrowed_box.rs | 2 +- clippy_lints/src/types/box_vec.rs | 3 +-- clippy_lints/src/types/linked_list.rs | 3 +-- clippy_lints/src/types/mod.rs | 8 ++++---- clippy_lints/src/types/option_option.rs | 3 +-- clippy_lints/src/types/rc_buffer.rs | 3 +-- clippy_lints/src/types/redundant_allocation.rs | 3 +-- clippy_lints/src/types/utils.rs | 6 ++---- clippy_lints/src/types/vec_box.rs | 3 +-- clippy_lints/src/undropped_manually_drops.rs | 2 +- clippy_lints/src/unicode.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 7 +++---- clippy_lints/src/unit_types/unit_arg.rs | 8 +++----- clippy_lints/src/unit_types/unit_cmp.rs | 3 +-- clippy_lints/src/unnamed_address.rs | 2 +- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/unnecessary_wraps.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 4 ++-- clippy_lints/src/unused_io_amount.rs | 2 +- clippy_lints/src/unused_self.rs | 3 +-- clippy_lints/src/unused_unit.rs | 3 +-- clippy_lints/src/unwrap.rs | 2 +- clippy_lints/src/unwrap_in_result.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/useless_conversion.rs | 4 ++-- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/inspector.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 3 +-- clippy_lints/src/utils/mod.rs | 2 -- clippy_lints/src/vec.rs | 2 +- clippy_lints/src/vec_init_then_push.rs | 2 +- clippy_lints/src/vec_resize_to_zero.rs | 7 +++---- clippy_lints/src/verbose_file_reads.rs | 2 +- clippy_lints/src/wildcard_dependencies.rs | 2 +- clippy_lints/src/wildcard_imports.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 3 +-- 243 files changed, 344 insertions(+), 399 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index bae4d4957a9..16905781c56 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -1,7 +1,7 @@ use crate::consts::{constant, Constant}; -use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call}; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_opt; +use clippy_utils::{is_direct_expn_of, is_expn_of, match_panic_call}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 8581e176e0c..5b8fb9b436a 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -1,8 +1,8 @@ -use crate::utils::{eq_expr_value, get_trait_def_id, trait_ref_of_method}; -use crate::utils::{higher, sugg}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use clippy_utils::ty::implements_trait; +use clippy_utils::{eq_expr_value, get_trait_def_id, trait_ref_of_method}; +use clippy_utils::{higher, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps { $($trait_name:ident),+) => { match $op { $(hir::BinOpKind::$trait_name => { - let [krate, module] = crate::utils::paths::OPS_MODULE; + let [krate, module] = clippy_utils::paths::OPS_MODULE; let path: [&str; 3] = [krate, module, concat!(stringify!($trait_name), "Assign")]; let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) { trait_id diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 231e74e16c0..dfb18199325 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -1,5 +1,5 @@ -use crate::utils::match_def_path; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::match_def_path; use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 6be6722375d..f805f716e6b 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -1,7 +1,7 @@ //! checks for attributes -use crate::utils::match_panic_def_id; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::match_panic_def_id; use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments}; use if_chain::if_chain; use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 3a3296c2c3d..68eee0520b3 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -1,5 +1,5 @@ -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint_and_note; +use clippy_utils::{match_def_path, paths}; use rustc_hir::def_id::DefId; use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 2b8400344f5..f7daf3dab49 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -1,6 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::sugg::Sugg; use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; +use clippy_utils::sugg::Sugg; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 343c4821c56..badcf8d2a43 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -1,7 +1,7 @@ -use crate::utils::{differing_macro_contexts, get_parent_expr}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet_block_with_applicability; use clippy_utils::ty::implements_trait; +use clippy_utils::{differing_macro_contexts, get_parent_expr}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 1303613b8c4..58d9aa9c005 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -1,7 +1,7 @@ -use crate::utils::{eq_expr_value, get_trait_def_id, in_macro, paths}; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; +use clippy_utils::{eq_expr_value, get_trait_def_id, in_macro, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index c1ca787c1e5..846ac08e93a 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -1,7 +1,7 @@ -use crate::utils::{contains_name, get_pat_name, paths, single_segment_path}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::match_type; +use clippy_utils::{contains_name, get_pat_name, paths, single_segment_path}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp}; diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index f0ef482164a..fce5c559672 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -2,8 +2,8 @@ use std::path::PathBuf; -use crate::utils::run_lints; use clippy_utils::diagnostics::span_lint; +use clippy_utils::run_lints; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/casts/cast_lossless.rs b/clippy_lints/src/casts/cast_lossless.rs index 4b660188d82..869deecfbd5 100644 --- a/clippy_lints/src/casts/cast_lossless.rs +++ b/clippy_lints/src/casts/cast_lossless.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_constant; use clippy_utils::source::snippet_opt; use clippy_utils::ty::is_isize_or_usize; use rustc_errors::Applicability; @@ -6,8 +7,6 @@ use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; -use crate::utils::in_constant; - use super::{utils, CAST_LOSSLESS}; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 75d7c55b637..833ad122e0d 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -1,10 +1,9 @@ +use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::is_isize_or_usize; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; -use clippy_utils::diagnostics::span_lint; - use super::{utils, CAST_POSSIBLE_TRUNCATION}; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 6a45ec61c54..5208156ffd2 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -1,14 +1,12 @@ use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_hir_ty_cfg_dependant; +use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, GenericArg}; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::sym; use rustc_target::abi::LayoutOf; -use if_chain::if_chain; - -use crate::utils::is_hir_ty_cfg_dependant; - use super::CAST_PTR_ALIGNMENT; pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs index 2965a840a82..bf722d0a3f4 100644 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ b/clippy_lints/src/casts/cast_sign_loss.rs @@ -1,13 +1,11 @@ +use crate::consts::{constant, Constant}; +use clippy_utils::diagnostics::span_lint; +use clippy_utils::{method_chain_args, sext}; +use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; -use if_chain::if_chain; - -use crate::consts::{constant, Constant}; -use crate::utils::{method_chain_args, sext}; -use clippy_utils::diagnostics::span_lint; - use super::CAST_SIGN_LOSS; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index b726bd75f1d..d9e172c01a7 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -12,14 +12,13 @@ mod ptr_as_ptr; mod unnecessary_cast; mod utils; +use clippy_utils::is_hir_ty_cfg_dependant; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use crate::utils::is_hir_ty_cfg_dependant; - declare_clippy_lint! { /// **What it does:** Checks for casts from any numerical to a float type where /// the receiving type cannot store all values from the original type without diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index 2c25f865cb8..9113e5a0920 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -1,17 +1,15 @@ use std::borrow::Cow; +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::meets_msrv; +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; use rustc_middle::ty::{self, TypeAndMut}; use rustc_semver::RustcVersion; -use if_chain::if_chain; - -use crate::utils::meets_msrv; -use crate::utils::sugg::Sugg; -use clippy_utils::diagnostics::span_lint_and_sugg; - use super::PTR_AS_PTR; const PTR_AS_PTR_MSRV: RustcVersion = RustcVersion::new(1, 38, 0); diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index a84e658024a..9ed359922fd 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::numeric_literal::NumericLiteral; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::{LitFloatType, LitIntType, LitKind}; @@ -8,8 +9,6 @@ use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, FloatTy, InferTy, Ty}; -use crate::utils::numeric_literal::NumericLiteral; - use super::UNNECESSARY_CAST; pub(super) fn check( diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 8b62e315e04..ed46cac493a 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::{meets_msrv, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; @@ -11,8 +12,6 @@ use rustc_middle::lint::in_external_macro; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use crate::utils::{meets_msrv, SpanlessEq}; - const CHECKED_CONVERSIONS_MSRV: RustcVersion = RustcVersion::new(1, 34, 0); declare_clippy_lint! { diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 8134f3af3ef..4cc542f723c 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_opt; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::LimitStack; use rustc_ast::ast::Attribute; use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId}; @@ -12,8 +13,6 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::{sym, BytePos}; -use crate::utils::LimitStack; - declare_clippy_lint! { /// **What it does:** Checks for methods with high cognitive complexity. /// diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index dbe70f90732..dae5c86bd44 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -14,14 +14,13 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet_block, snippet_block_with_applicability}; +use clippy_utils::sugg::Sugg; use if_chain::if_chain; use rustc_ast::ast; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::sugg::Sugg; - declare_clippy_lint! { /// **What it does:** Checks for nested `if` statements which can be collapsed /// by `&&`-combining their conditions. diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index 5ff2518bd94..e2b3686ddf0 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -1,6 +1,6 @@ -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{path_to_local, SpanlessEq}; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::visitors::LocalUsedVisitor; +use clippy_utils::{path_to_local, SpanlessEq}; use if_chain::if_chain; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, QPath, StmtKind, UnOp}; diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 5411905791c..d601cb7c224 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -1,6 +1,6 @@ -use crate::utils::{get_trait_def_id, if_sequence, parent_node_is_if_expr, paths, SpanlessEq}; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::implements_trait; +use clippy_utils::{get_trait_def_id, if_sequence, parent_node_is_if_expr, paths, SpanlessEq}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index f86f0da6d6f..46093a16571 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -1,6 +1,6 @@ -use crate::utils::{eq_expr_value, in_macro, search_same, SpanlessEq, SpanlessHash}; -use crate::utils::{get_parent_expr, if_sequence}; use clippy_utils::diagnostics::span_lint_and_note; +use clippy_utils::{eq_expr_value, in_macro, search_same, SpanlessEq, SpanlessHash}; +use clippy_utils::{get_parent_expr, if_sequence}; use rustc_hir::{Block, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/create_dir.rs b/clippy_lints/src/create_dir.rs index 01ca2837a99..ac890c90c97 100644 --- a/clippy_lints/src/create_dir.rs +++ b/clippy_lints/src/create_dir.rs @@ -1,6 +1,6 @@ -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 0b074c088d4..d046e894792 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -1,6 +1,6 @@ -use crate::utils::{any_parent_is_automatically_derived, contains_name, match_def_path, paths}; use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg}; use clippy_utils::source::snippet_with_macro_callsite; +use clippy_utils::{any_parent_is_automatically_derived, contains_name, match_def_path, paths}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 62ec2f8ce48..1415f8e235a 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1,7 +1,7 @@ -use crate::utils::{get_parent_node, in_macro, is_allowed}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::peel_mid_ty_refs; +use clippy_utils::{get_parent_node, in_macro, is_allowed}; use rustc_ast::util::parser::PREC_PREFIX; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, UnOp}; diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index a7f2106e357..834136f910d 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -1,7 +1,7 @@ -use crate::utils::paths; -use crate::utils::{get_trait_def_id, is_allowed, is_automatically_derived, match_def_path}; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_then}; +use clippy_utils::paths; use clippy_utils::ty::is_copy; +use clippy_utils::{get_trait_def_id, is_allowed, is_automatically_derived, match_def_path}; use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/disallowed_method.rs b/clippy_lints/src/disallowed_method.rs index 16023bc53b0..ded0a0fff54 100644 --- a/clippy_lints/src/disallowed_method.rs +++ b/clippy_lints/src/disallowed_method.rs @@ -1,5 +1,5 @@ -use crate::utils::fn_def_id; use clippy_utils::diagnostics::span_lint; +use clippy_utils::fn_def_id; use rustc_data_structures::fx::FxHashSet; use rustc_hir::Expr; diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index d9952325c4b..5fa278b2897 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -1,6 +1,6 @@ -use crate::utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty}; use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; +use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty}; use if_chain::if_chain; use itertools::Itertools; use rustc_ast::ast::{Async, AttrKind, Attribute, FnKind, FnRetTy, ItemKind}; diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 549720feb2d..1d291565ec1 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -1,6 +1,7 @@ //! Lint on unnecessary double comparisons. Some examples: use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::eq_expr_value; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; @@ -8,8 +9,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use crate::utils::eq_expr_value; - declare_clippy_lint! { /// **What it does:** Checks for double comparisons that could be simplified to a single expression. /// diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index fe86adcec45..7e7ec017bbb 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -1,6 +1,6 @@ -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::ty::is_copy; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 40c75f568ae..746c1f6df91 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -8,8 +8,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; use crate::consts::{constant, Constant}; -use crate::utils::paths; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::paths; declare_clippy_lint! { /// **What it does:** Checks for calculation of subsecond microseconds or milliseconds diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index cc774831491..25eb048448c 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -1,8 +1,8 @@ -use crate::utils::SpanlessEq; -use crate::utils::{get_item_name, paths}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability}; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; +use clippy_utils::SpanlessEq; +use clippy_utils::{get_item_name, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index d2d8acb443b..0ecc0bc3eb6 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -1,6 +1,6 @@ //! lint on enum variants that are prefixed or suffixed by the same characters -use crate::utils::camel_case; +use clippy_utils::camel_case; use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use clippy_utils::source::is_present_in_source; use rustc_ast::ast::{EnumDef, Item, ItemKind, VisibilityKind}; diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 1b2f66fb628..6d7046ac8b7 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -1,7 +1,7 @@ -use crate::utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of}; use clippy_utils::diagnostics::{multispan_sugg, span_lint, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::{implements_trait, is_copy}; +use clippy_utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, StmtKind}; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 2557e9f2796..99253555a95 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -3,6 +3,7 @@ use clippy_utils::higher; use clippy_utils::higher::VecArgs; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{implements_trait, type_is_unsafe_function}; +use clippy_utils::{is_adjusted, iter_input_pats}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{def_id, Expr, ExprKind, Param, PatKind, QPath}; @@ -11,8 +12,6 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{is_adjusted, iter_input_pats}; - declare_clippy_lint! { /// **What it does:** Checks for closures which just call another function where /// the function can be called directly. `unsafe` functions or calls where types diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 3711ba4a7ee..5d5b67de843 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -1,5 +1,5 @@ -use crate::utils::{get_parent_expr, path_to_local, path_to_local_id}; use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; +use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id}; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 683e0435351..6c9652fd87d 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -1,5 +1,5 @@ -use crate::utils::{attr_by_name, in_macro, match_path_ast}; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::{attr_by_name, in_macro, match_path_ast}; use rustc_ast::ast::{AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index adfb644b199..635b6d83eab 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -1,5 +1,5 @@ -use crate::utils::{is_entrypoint_fn, match_def_path, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{is_entrypoint_fn, match_def_path, paths}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 0861cba4675..4146b7baa10 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -1,5 +1,5 @@ -use crate::utils::{is_expn_of, match_function_call, paths}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::{is_expn_of, match_function_call, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 5efe465a667..52a5a7acf0d 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -1,6 +1,6 @@ -use crate::utils::{is_expn_of, match_panic_def_id, method_chain_args}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{is_expn_of, match_panic_def_id, method_chain_args}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/float_equality_without_abs.rs b/clippy_lints/src/float_equality_without_abs.rs index b3593d328cc..0c59db360f9 100644 --- a/clippy_lints/src/float_equality_without_abs.rs +++ b/clippy_lints/src/float_equality_without_abs.rs @@ -1,5 +1,5 @@ -use crate::utils::{match_def_path, paths, sugg}; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::{match_def_path, paths, sugg}; use if_chain::if_chain; use rustc_ast::util::parser::AssocOp; use rustc_errors::Applicability; diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 6446fe62a64..1ca5c685a75 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -1,5 +1,5 @@ -use crate::utils::numeric_literal; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::numeric_literal; use if_chain::if_chain; use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 8b53384ecbd..0b5f0379ce6 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -2,8 +2,8 @@ use crate::consts::{ constant, constant_simple, Constant, Constant::{Int, F32, F64}, }; -use crate::utils::{eq_expr_value, get_parent_expr, numeric_literal, sugg}; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::{eq_expr_value, get_parent_expr, numeric_literal, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp}; diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index db27225707d..a33f987b423 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -1,8 +1,8 @@ -use crate::utils::paths; -use crate::utils::{is_expn_of, last_path_segment, match_def_path, match_function_call}; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::paths; use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{is_expn_of, last_path_segment, match_def_path, match_function_call}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 4dadd2ba936..b10e83c0ea8 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -1,5 +1,5 @@ -use crate::utils::differing_macro_contexts; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note}; +use clippy_utils::differing_macro_contexts; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 5eea4d14759..e5ec245e502 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -1,6 +1,6 @@ -use crate::utils::paths::INTO; -use crate::utils::{match_def_path, meets_msrv}; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::paths::INTO; +use clippy_utils::{match_def_path, meets_msrv}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index b9a44f26381..3da5bc95b6d 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; @@ -8,8 +9,6 @@ use rustc_middle::ty::Ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; -use crate::utils::sugg::Sugg; - declare_clippy_lint! { /// **What it does:** /// Checks for function invocations of the form `primitive::from_str_radix(s, 10)` diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 37288d7a0b2..730492fc7e3 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -1,10 +1,10 @@ -use crate::utils::{ - attr_by_name, attrs::is_proc_macro, is_trait_impl_item, iter_input_pats, match_def_path, must_use_attr, - path_to_local, return_ty, trait_ref_of_method, -}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_then}; use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::{is_must_use_ty, is_type_diagnostic_item, type_is_unsafe_function}; +use clippy_utils::{ + attr_by_name, attrs::is_proc_macro, is_trait_impl_item, iter_input_pats, match_def_path, must_use_attr, + path_to_local, return_ty, trait_ref_of_method, +}; use if_chain::if_chain; use rustc_ast::ast::Attribute; use rustc_data_structures::fx::FxHashSet; diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 36960e7f51b..04730ace887 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -1,5 +1,5 @@ -use crate::utils; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::return_ty; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { if let FnKind::Closure = kind { return; } - let ret_ty = utils::return_ty(cx, hir_id); + let ret_ty = return_ty(cx, hir_id); if let Opaque(id, subst) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(id); let mut is_future = false; diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index 6f14ede0ecb..cbcef567c53 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -1,9 +1,9 @@ //! lint on using `x.get(x.len() - 1)` instead of `x.last()` -use crate::utils::SpanlessEq; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::SpanlessEq; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 385ea020328..8bed5e1bf64 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -7,8 +7,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use crate::consts::{constant_simple, Constant}; -use crate::utils::{clip, unsext}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{clip, unsext}; declare_clippy_lint! { /// **What it does:** Checks for identity operations, e.g., `x + 0`. diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index c2ec8b3ffd1..4aab43256bf 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -1,6 +1,6 @@ -use crate::utils::SpanlessEq; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::SpanlessEq; use if_chain::if_chain; use rustc_hir::intravisit::{self as visit, NestedVisitorMap, Visitor}; use rustc_hir::{Expr, ExprKind, MatchSource}; diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 59094d1147a..6e9280c8c7e 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -1,5 +1,5 @@ -use crate::utils::method_chain_args; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::method_chain_args; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index c4e87300b7b..0b5bf060d4c 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -1,6 +1,6 @@ -use crate::utils; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_with_macro_callsite; +use clippy_utils::{match_qpath, meets_msrv, parent_node_is_if_expr}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -58,7 +58,7 @@ impl_lint_pass!(IfThenSomeElseNone => [IF_THEN_SOME_ELSE_NONE]); impl LateLintPass<'_> for IfThenSomeElseNone { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) { - if !utils::meets_msrv(self.msrv.as_ref(), &IF_THEN_SOME_ELSE_NONE_MSRV) { + if !meets_msrv(self.msrv.as_ref(), &IF_THEN_SOME_ELSE_NONE_MSRV) { return; } @@ -67,7 +67,7 @@ impl LateLintPass<'_> for IfThenSomeElseNone { } // We only care about the top-most `if` in the chain - if utils::parent_node_is_if_expr(expr, cx) { + if parent_node_is_if_expr(expr, cx) { return; } @@ -77,12 +77,12 @@ impl LateLintPass<'_> for IfThenSomeElseNone { if let Some(ref then_expr) = then_block.expr; if let ExprKind::Call(ref then_call, [then_arg]) = then_expr.kind; if let ExprKind::Path(ref then_call_qpath) = then_call.kind; - if utils::match_qpath(then_call_qpath, &utils::paths::OPTION_SOME); + if match_qpath(then_call_qpath, &clippy_utils::paths::OPTION_SOME); if let ExprKind::Block(ref els_block, _) = els.kind; if els_block.stmts.is_empty(); if let Some(ref els_expr) = els_block.expr; if let ExprKind::Path(ref els_call_qpath) = els_expr.kind; - if utils::match_qpath(els_call_qpath, &utils::paths::OPTION_NONE); + if match_qpath(els_call_qpath, &clippy_utils::paths::OPTION_NONE); then { let cond_snip = snippet_with_macro_callsite(cx, cond.span, "[condition]"); let cond_snip = if matches!(cond.kind, ExprKind::Unary(_, _) | ExprKind::Binary(_, _, _)) { diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 70ea9a92279..6863645a92d 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -1,5 +1,5 @@ -use crate::utils::match_panic_def_id; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::match_panic_def_id; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 3d2798f3fb4..5207c628987 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -1,5 +1,5 @@ -use crate::utils::{in_macro, match_qpath, SpanlessEq}; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::{in_macro, match_qpath, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 4c0f976f79a..94d39019608 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -1,8 +1,8 @@ //! lint on indexing and slicing operations use crate::consts::{constant, Constant}; -use crate::utils::higher; use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; +use clippy_utils::higher; use rustc_ast::ast::RangeLimits; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index addd95c6eae..fb35bc1e780 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -1,11 +1,10 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::{implements_trait, match_type}; +use clippy_utils::{get_trait_def_id, higher, match_qpath, paths}; use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{get_trait_def_id, higher, match_qpath, paths}; - declare_clippy_lint! { /// **What it does:** Checks for iteration that is guaranteed to be infinite. /// diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index f838ce190dc..5b2e70e3ce9 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -1,7 +1,7 @@ //! lint on inherent implementations -use crate::utils::in_macro; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::in_macro; use rustc_data_structures::fx::FxHashMap; use rustc_hir::{def_id, Crate, Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 6b29feeb4ed..b023e13e846 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -1,13 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; +use clippy_utils::{get_trait_def_id, paths, return_ty, trait_ref_of_method}; use if_chain::if_chain; use rustc_hir::{ImplItem, ImplItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -use crate::utils::{get_trait_def_id, paths, return_ty, trait_ref_of_method}; - declare_clippy_lint! { /// **What it does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`. /// diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 87fe5123cf6..20f00bd51ba 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -1,7 +1,7 @@ //! checks for `#[inline]` on trait methods without bodies -use crate::utils::sugg::DiagnosticBuilderExt; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg::DiagnosticBuilderExt; use rustc_ast::ast::Attribute; use rustc_errors::Applicability; use rustc_hir::{TraitFn, TraitItem, TraitItemKind}; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index a644a4113ae..717f2ea84f4 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -1,6 +1,6 @@ -use crate::utils::{get_item_name, get_parent_as_impl, is_allowed}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::{get_item_name, get_parent_as_impl, is_allowed}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_data_structures::fx::FxHashSet; diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 4b7e02398fb..2d7d9c9befb 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -1,6 +1,6 @@ -use crate::utils::{path_to_local_id, visitors::LocalUsedVisitor}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; +use clippy_utils::{path_to_local_id, visitors::LocalUsedVisitor}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index eee2503b481..7e3a76ded2c 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -1,5 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_must_use_ty, match_type}; +use clippy_utils::{is_must_use_func_call, paths}; use if_chain::if_chain; use rustc_hir::{Local, PatKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -7,8 +8,6 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{is_must_use_func_call, paths}; - declare_clippy_lint! { /// **What it does:** Checks for `let _ = ` /// where expr is #[must_use] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index f479d756a33..9b2876ddc11 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -42,7 +42,7 @@ extern crate rustc_target; extern crate rustc_trait_selection; extern crate rustc_typeck; -use crate::utils::parse_msrv; +use clippy_utils::parse_msrv; use rustc_data_structures::fx::FxHashSet; use rustc_lint::LintId; use rustc_session::Session; diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 0848aaed815..a2f093e6ef7 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -1,5 +1,5 @@ -use crate::utils::{in_macro, trait_ref_of_method}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{in_macro, trait_ref_of_method}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::intravisit::{ walk_fn_decl, walk_generic_param, walk_generics, walk_item, walk_param_bound, walk_poly_trait_ref, walk_ty, diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index dd303bc0a01..7fd55151226 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -1,12 +1,12 @@ //! Lints concerned with the grouping of digits with underscores in integral or //! floating-point literal expressions. -use crate::utils::{ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::snippet_opt; +use clippy_utils::{ in_macro, numeric_literal::{NumericLiteral, Radix}, }; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind, Lit, LitKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/empty_loop.rs b/clippy_lints/src/loops/empty_loop.rs index d52a061fc8f..dda09fecdf9 100644 --- a/clippy_lints/src/loops/empty_loop.rs +++ b/clippy_lints/src/loops/empty_loop.rs @@ -1,6 +1,6 @@ use super::EMPTY_LOOP; -use crate::utils::{is_in_panic_handler, is_no_std_crate}; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::{is_in_panic_handler, is_no_std_crate}; use rustc_hir::{Block, Expr}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/loops/explicit_counter_loop.rs b/clippy_lints/src/loops/explicit_counter_loop.rs index 87ce4e4c20c..f14dbb1d642 100644 --- a/clippy_lints/src/loops/explicit_counter_loop.rs +++ b/clippy_lints/src/loops/explicit_counter_loop.rs @@ -1,9 +1,9 @@ use super::{ get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP, }; -use crate::utils::{get_enclosing_block, is_integer_const}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::{get_enclosing_block, is_integer_const}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_block, walk_expr}; diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 259e95e5ef4..92aa2beb66d 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -1,8 +1,8 @@ use super::EXPLICIT_ITER_LOOP; -use crate::utils::{match_trait_method, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; +use clippy_utils::{match_trait_method, paths}; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/loops/for_kv_map.rs b/clippy_lints/src/loops/for_kv_map.rs index bf037f392e0..8f18f54119b 100644 --- a/clippy_lints/src/loops/for_kv_map.rs +++ b/clippy_lints/src/loops/for_kv_map.rs @@ -1,9 +1,9 @@ use super::FOR_KV_MAP; -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{paths, sugg}; use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; +use clippy_utils::visitors::LocalUsedVisitor; +use clippy_utils::{paths, sugg}; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind}; use rustc_lint::LateContext; use rustc_middle::ty; diff --git a/clippy_lints/src/loops/iter_next_loop.rs b/clippy_lints/src/loops/iter_next_loop.rs index 27a03562800..9148fbfd497 100644 --- a/clippy_lints/src/loops/iter_next_loop.rs +++ b/clippy_lints/src/loops/iter_next_loop.rs @@ -1,11 +1,10 @@ use super::ITER_NEXT_LOOP; use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_trait_method; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_span::sym; -use crate::utils::is_trait_method; - pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, expr: &Expr<'_>) -> bool { if is_trait_method(cx, arg, sym::Iterator) { span_lint( diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 43580d6071a..be87f67d300 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -1,7 +1,7 @@ use super::utils::make_iterator_snippet; use super::MANUAL_FLATTEN; -use crate::utils::{is_ok_ctor, is_some_ctor, path_to_local_id}; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::{is_ok_ctor, is_some_ctor, path_to_local_id}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatKind, QPath, StmtKind}; diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index ff68d136999..af6d56a89af 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -1,9 +1,9 @@ use super::{get_span_of_entire_for_loop, IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY}; -use crate::utils::sugg::Sugg; -use crate::utils::{get_enclosing_block, higher, path_to_local, sugg}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{get_enclosing_block, higher, path_to_local, sugg}; use if_chain::if_chain; use rustc_ast::ast; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 2a372c6307e..20291491998 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -18,7 +18,7 @@ mod while_immutable_condition; mod while_let_loop; mod while_let_on_iterator; -use crate::utils::higher; +use clippy_utils::higher; use rustc_hir::{Expr, ExprKind, LoopSource, Pat}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 175aee53a9a..f4e4064ba1d 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -1,6 +1,6 @@ use super::MUT_RANGE_BOUND; -use crate::utils::{higher, path_to_local}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{higher, path_to_local}; use if_chain::if_chain; use rustc_hir::{BindingAnnotation, Expr, HirId, Node, PatKind}; use rustc_infer::infer::TyCtxtInferExt; diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index a3b731eefa0..5594fc7b046 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -1,9 +1,9 @@ use super::NEEDLESS_COLLECT; -use crate::utils::sugg::Sugg; -use crate::utils::{is_trait_method, path_to_local_id, paths}; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; +use clippy_utils::{is_trait_method, path_to_local_id, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_block, walk_expr, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index ca679d7ebe1..3c40d54cb42 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -1,11 +1,11 @@ use super::NEEDLESS_RANGE_LOOP; -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{ - contains_name, higher, is_integer_const, match_trait_method, path_to_local_id, paths, sugg, SpanlessEq, -}; use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::has_iter_method; +use clippy_utils::visitors::LocalUsedVisitor; +use clippy_utils::{ + contains_name, higher, is_integer_const, match_trait_method, path_to_local_id, paths, sugg, SpanlessEq, +}; use if_chain::if_chain; use rustc_ast::ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; diff --git a/clippy_lints/src/loops/single_element_loop.rs b/clippy_lints/src/loops/single_element_loop.rs index 172eb963ae3..8451c1c6130 100644 --- a/clippy_lints/src/loops/single_element_loop.rs +++ b/clippy_lints/src/loops/single_element_loop.rs @@ -1,6 +1,6 @@ use super::{get_span_of_entire_for_loop, SINGLE_ELEMENT_LOOP}; -use crate::utils::single_segment_path; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::single_segment_path; use clippy_utils::source::{indent_of, snippet}; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index b85676570b4..bb409c48532 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -1,5 +1,5 @@ -use crate::utils::{get_parent_expr, is_integer_const, path_to_local, path_to_local_id, sugg}; use clippy_utils::ty::{has_iter_method, implements_trait}; +use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_local_id, sugg}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/while_immutable_condition.rs b/clippy_lints/src/loops/while_immutable_condition.rs index a037a06de81..cad9ff8489a 100644 --- a/clippy_lints/src/loops/while_immutable_condition.rs +++ b/clippy_lints/src/loops/while_immutable_condition.rs @@ -1,7 +1,7 @@ use super::WHILE_IMMUTABLE_CONDITION; use crate::consts::constant; -use crate::utils::usage::mutated_variables; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::usage::mutated_variables; use if_chain::if_chain; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::{DefKind, Res}; diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index 29ad9e735cc..57fc6250a9a 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -1,12 +1,12 @@ use super::utils::{LoopNestVisitor, Nesting}; use super::WHILE_LET_ON_ITERATOR; -use crate::utils::usage::mutated_variables; -use crate::utils::{ - get_enclosing_block, is_refutable, is_trait_method, last_path_segment, path_to_local, path_to_local_id, -}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::implements_trait; +use clippy_utils::usage::mutated_variables; +use clippy_utils::{ + get_enclosing_block, is_refutable, is_trait_method, last_path_segment, path_to_local, path_to_local_id, +}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_block, walk_expr, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 92f95645734..d573c297838 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -1,5 +1,5 @@ -use crate::utils::in_macro; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_macro; use clippy_utils::source::snippet; use hir::def::{DefKind, Res}; use if_chain::if_chain; diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 6c0308cbd92..07d8a440aea 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -1,12 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet; +use clippy_utils::{is_entrypoint_fn, is_no_std_crate}; use if_chain::if_chain; use rustc_hir::{Crate, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use crate::utils::{is_entrypoint_fn, is_no_std_crate}; - declare_clippy_lint! { /// **What it does:** Checks for recursion using the entrypoint. /// diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 1db5cf56962..5d88ff3b99f 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -1,6 +1,6 @@ -use crate::utils::match_function_call; -use crate::utils::paths::FUTURE_FROM_GENERATOR; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::match_function_call; +use clippy_utils::paths::FUTURE_FROM_GENERATOR; use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt}; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index fd563bec769..cd9594737bf 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -1,11 +1,8 @@ -use crate::{ - map_unit_fn::OPTION_MAP_UNIT_FN, - matches::MATCH_AS_REF, - utils::{is_allowed, match_def_path, match_var, paths, peel_hir_expr_refs}, -}; +use crate::{map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::ty::{can_partially_move_ty, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable}; +use clippy_utils::{is_allowed, match_def_path, match_var, paths, peel_hir_expr_refs}; use rustc_ast::util::parser::PREC_POSTFIX; use rustc_errors::Applicability; use rustc_hir::{ diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 705c1ec1859..a9a89ae5659 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -1,5 +1,5 @@ -use crate::utils::meets_msrv; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::meets_msrv; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantData, VisibilityKind}; diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index a1e5c752f83..9bfae602c40 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -1,7 +1,7 @@ -use crate::utils::{match_qpath, path_to_local_id, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt}; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{match_qpath, path_to_local_id, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, PatKind}; diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index bc4e255b03d..9da37efddac 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -1,8 +1,8 @@ use crate::consts::{constant, Constant}; -use crate::utils::usage::mutated_variables; -use crate::utils::{eq_expr_value, higher, match_def_path, meets_msrv, paths}; use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; +use clippy_utils::usage::mutated_variables; +use clippy_utils::{eq_expr_value, higher, match_def_path, meets_msrv, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_hir::def::Res; diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 615e2d5c2af..4f139f8d39a 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -1,9 +1,9 @@ use crate::consts::constant_simple; -use crate::utils; -use crate::utils::{in_constant, path_to_local_id, sugg}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt}; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::usage::contains_return_break_continue_macro; +use clippy_utils::{in_constant, match_qpath, path_to_local_id, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Arm, Expr, ExprKind, Pat, PatKind}; @@ -75,19 +75,19 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| match arm.pat.kind { PatKind::Path(ref some_qpath) => - utils::match_qpath(some_qpath, &utils::paths::OPTION_NONE), + match_qpath(some_qpath, &clippy_utils::paths::OPTION_NONE), PatKind::TupleStruct(ref err_qpath, &[Pat { kind: PatKind::Wild, .. }], _) => - utils::match_qpath(err_qpath, &utils::paths::RESULT_ERR), + match_qpath(err_qpath, &clippy_utils::paths::RESULT_ERR), _ => false, } ); let unwrap_arm = &arms[1 - idx]; if let PatKind::TupleStruct(ref unwrap_qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind; - if utils::match_qpath(unwrap_qpath, &utils::paths::OPTION_SOME) - || utils::match_qpath(unwrap_qpath, &utils::paths::RESULT_OK); + if match_qpath(unwrap_qpath, &clippy_utils::paths::OPTION_SOME) + || match_qpath(unwrap_qpath, &clippy_utils::paths::RESULT_OK); if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind; if path_to_local_id(unwrap_arm.body, binding_hir_id); - if !utils::usage::contains_return_break_continue_macro(or_arm.body); + if !contains_return_break_continue_macro(or_arm.body); then { Some(or_arm) } else { diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index fd39052871b..cfcc705eabc 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -1,6 +1,6 @@ -use crate::utils::is_trait_method; -use crate::utils::remove_blocks; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_trait_method; +use clippy_utils::remove_blocks; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_copy, is_type_diagnostic_item}; use if_chain::if_chain; diff --git a/clippy_lints/src/map_identity.rs b/clippy_lints/src/map_identity.rs index 84ec23c4e2f..75191e1f9ee 100644 --- a/clippy_lints/src/map_identity.rs +++ b/clippy_lints/src/map_identity.rs @@ -1,6 +1,6 @@ -use crate::utils::{is_adjusted, is_trait_method, match_path, match_var, paths, remove_blocks}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{is_adjusted, is_trait_method, match_path, match_var, paths, remove_blocks}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Body, Expr, ExprKind, Pat, PatKind, QPath, StmtKind}; diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 3bd4a965765..d4764b5ccff 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -1,7 +1,7 @@ -use crate::utils::{iter_input_pats, method_chain_args}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{iter_input_pats, method_chain_args}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 1aa09b82822..e94c7094cac 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1,16 +1,16 @@ use crate::consts::{constant, miri_to_const, Constant}; -use crate::utils::sugg::Sugg; -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{ - get_parent_expr, in_macro, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath, meets_msrv, path_to_local, - path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, remove_blocks, strip_pat_refs, -}; -use crate::utils::{paths, search_same, SpanlessEq, SpanlessHash}; use clippy_utils::diagnostics::{ multispan_sugg, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, }; use clippy_utils::source::{expr_block, indent_of, snippet, snippet_block, snippet_opt, snippet_with_applicability}; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs}; +use clippy_utils::visitors::LocalUsedVisitor; +use clippy_utils::{ + get_parent_expr, in_macro, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath, meets_msrv, path_to_local, + path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, remove_blocks, strip_pat_refs, +}; +use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -1616,9 +1616,9 @@ where mod redundant_pattern_match { use super::REDUNDANT_PATTERN_MATCHING; - use crate::utils::{is_trait_method, match_qpath, paths}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; + use clippy_utils::{is_trait_method, match_qpath, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index 85353d4cdde..7895ba9f1e0 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -1,7 +1,7 @@ -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::walk_ptrs_ty_depth; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind}; diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index 1a8cb82514b..c13802e3953 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -1,5 +1,5 @@ -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{match_def_path, paths}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 87cb66a6770..426c108d89f 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -1,7 +1,7 @@ -use crate::utils::{in_macro, match_def_path, match_qpath, meets_msrv, paths}; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::is_diagnostic_assoc_item; use clippy_utils::source::{snippet, snippet_with_applicability}; +use clippy_utils::{in_macro, match_def_path, match_qpath, meets_msrv, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 7d6104ebb7f..0ba8a98a018 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -1,8 +1,8 @@ use super::{contains_return, BIND_INSTEAD_OF_MAP}; -use crate::utils::{in_macro, match_qpath, method_calls, paths, remove_blocks, visitors::find_all_ret_expressions}; use clippy_utils::diagnostics::{multispan_sugg_with_applicability, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet, snippet_with_macro_callsite}; use clippy_utils::ty::match_type; +use clippy_utils::{in_macro, match_qpath, method_calls, paths, remove_blocks, visitors::find_all_ret_expressions}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index d1c7789a241..949152cf789 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -1,5 +1,5 @@ -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use clippy_utils::ty::is_copy; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/clone_on_ref_ptr.rs b/clippy_lints/src/methods/clone_on_ref_ptr.rs index b49ae42b12f..03c949d5c31 100644 --- a/clippy_lints/src/methods/clone_on_ref_ptr.rs +++ b/clippy_lints/src/methods/clone_on_ref_ptr.rs @@ -1,5 +1,5 @@ -use crate::utils::paths; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::paths; use clippy_utils::source::snippet_with_macro_callsite; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 1c673c11d65..e7bffa66b3f 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -1,5 +1,5 @@ -use crate::utils::is_expn_of; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_expn_of; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/filetype_is_file.rs b/clippy_lints/src/methods/filetype_is_file.rs index 005c94a6018..39d2f15dbc8 100644 --- a/clippy_lints/src/methods/filetype_is_file.rs +++ b/clippy_lints/src/methods/filetype_is_file.rs @@ -1,6 +1,6 @@ -use crate::utils::{get_parent_expr, paths}; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::match_type; +use clippy_utils::{get_parent_expr, paths}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/filter_flat_map.rs b/clippy_lints/src/methods/filter_flat_map.rs index 4820bb137c1..2f3a3c55ab5 100644 --- a/clippy_lints/src/methods/filter_flat_map.rs +++ b/clippy_lints/src/methods/filter_flat_map.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_trait_method; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index af91370df20..2cb476acb2b 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -1,6 +1,6 @@ -use crate::utils::{is_trait_method, path_to_local_id, SpanlessEq}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; +use clippy_utils::{is_trait_method, path_to_local_id, SpanlessEq}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/filter_map_flat_map.rs b/clippy_lints/src/methods/filter_map_flat_map.rs index 5294ef97528..b1a4dc98eb8 100644 --- a/clippy_lints/src/methods/filter_map_flat_map.rs +++ b/clippy_lints/src/methods/filter_map_flat_map.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_trait_method; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/filter_map_identity.rs b/clippy_lints/src/methods/filter_map_identity.rs index 4461baf4f7c..80598d88508 100644 --- a/clippy_lints/src/methods/filter_map_identity.rs +++ b/clippy_lints/src/methods/filter_map_identity.rs @@ -1,5 +1,5 @@ -use crate::utils::{is_trait_method, match_qpath, path_to_local_id, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::{is_trait_method, match_qpath, path_to_local_id, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/filter_map_map.rs b/clippy_lints/src/methods/filter_map_map.rs index 8f17350054b..0b0a8b1dd3b 100644 --- a/clippy_lints/src/methods/filter_map_map.rs +++ b/clippy_lints/src/methods/filter_map_map.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_trait_method; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/filter_map_next.rs b/clippy_lints/src/methods/filter_map_next.rs index 8fbadd1d457..ba57abd16c9 100644 --- a/clippy_lints/src/methods/filter_map_next.rs +++ b/clippy_lints/src/methods/filter_map_next.rs @@ -1,6 +1,6 @@ -use crate::utils::{is_trait_method, meets_msrv}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet; +use clippy_utils::{is_trait_method, meets_msrv}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index af16ea19007..6cd24334414 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::is_trait_method; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/flat_map_identity.rs b/clippy_lints/src/methods/flat_map_identity.rs index 669ac1f743f..034ea6c6562 100644 --- a/clippy_lints/src/methods/flat_map_identity.rs +++ b/clippy_lints/src/methods/flat_map_identity.rs @@ -1,5 +1,5 @@ -use crate::utils::{is_trait_method, match_qpath, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::{is_trait_method, match_qpath, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/from_iter_instead_of_collect.rs b/clippy_lints/src/methods/from_iter_instead_of_collect.rs index 5d0a07992c8..2095a60e44b 100644 --- a/clippy_lints/src/methods/from_iter_instead_of_collect.rs +++ b/clippy_lints/src/methods/from_iter_instead_of_collect.rs @@ -1,6 +1,6 @@ -use crate::utils::{get_trait_def_id, paths, sugg}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::implements_trait; +use clippy_utils::{get_trait_def_id, paths, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/get_unwrap.rs b/clippy_lints/src/methods/get_unwrap.rs index ac855419d00..b122a0a0b89 100644 --- a/clippy_lints/src/methods/get_unwrap.rs +++ b/clippy_lints/src/methods/get_unwrap.rs @@ -1,8 +1,8 @@ use crate::methods::derefs_to_slice; -use crate::utils::{get_parent_expr, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; +use clippy_utils::{get_parent_expr, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 56de7a8bc5e..d10a540c24e 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -1,8 +1,8 @@ use super::INEFFICIENT_TO_STRING; -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, walk_ptrs_ty_depth}; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/inspect_for_each.rs b/clippy_lints/src/methods/inspect_for_each.rs index c9bbfbc37eb..7fd3ef1a622 100644 --- a/clippy_lints/src/methods/inspect_for_each.rs +++ b/clippy_lints/src/methods/inspect_for_each.rs @@ -1,10 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_trait_method; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::{source_map::Span, sym}; -use crate::utils::is_trait_method; - use super::INSPECT_FOR_EACH; /// lint use of `inspect().for_each()` for `Iterators` diff --git a/clippy_lints/src/methods/into_iter_on_ref.rs b/clippy_lints/src/methods/into_iter_on_ref.rs index a862b55e139..cfe749cf361 100644 --- a/clippy_lints/src/methods/into_iter_on_ref.rs +++ b/clippy_lints/src/methods/into_iter_on_ref.rs @@ -1,6 +1,6 @@ -use crate::utils::{match_trait_method, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::has_iter_method; +use clippy_utils::{match_trait_method, paths}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/iter_count.rs b/clippy_lints/src/methods/iter_count.rs index bfd62ff1f0d..fd3d53816a1 100644 --- a/clippy_lints/src/methods/iter_count.rs +++ b/clippy_lints/src/methods/iter_count.rs @@ -1,6 +1,6 @@ use crate::methods::derefs_to_slice; -use crate::utils::paths; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::paths; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index ce599682bbe..feebf8b8209 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -1,8 +1,8 @@ use crate::methods::derefs_to_slice; -use crate::utils::{get_parent_expr, higher}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{get_parent_expr, higher}; use if_chain::if_chain; use rustc_ast::ast; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_nth_zero.rs b/clippy_lints/src/methods/iter_nth_zero.rs index f2b2dd8c097..a12f672739c 100644 --- a/clippy_lints/src/methods/iter_nth_zero.rs +++ b/clippy_lints/src/methods/iter_nth_zero.rs @@ -1,6 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_trait_method; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_skip_next.rs b/clippy_lints/src/methods/iter_skip_next.rs index 6100613bcac..ea01860b456 100644 --- a/clippy_lints/src/methods/iter_skip_next.rs +++ b/clippy_lints/src/methods/iter_skip_next.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_trait_method; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/iterator_step_by_zero.rs b/clippy_lints/src/methods/iterator_step_by_zero.rs index 51c1ab0484e..3baa580314f 100644 --- a/clippy_lints/src/methods/iterator_step_by_zero.rs +++ b/clippy_lints/src/methods/iterator_step_by_zero.rs @@ -1,6 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_trait_method; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 0c8a002e359..f16699322d1 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -1,5 +1,5 @@ -use crate::utils::match_qpath; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::match_qpath; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_ast::ast; diff --git a/clippy_lints/src/methods/map_collect_result_unit.rs b/clippy_lints/src/methods/map_collect_result_unit.rs index b59998fc8b4..e4402b2da21 100644 --- a/clippy_lints/src/methods/map_collect_result_unit.rs +++ b/clippy_lints/src/methods/map_collect_result_unit.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_trait_method; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index 6f5e723fbfb..4bc52b036a8 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_trait_method; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/map_unwrap_or.rs b/clippy_lints/src/methods/map_unwrap_or.rs index 8ef02b4a641..deb4b4492b5 100644 --- a/clippy_lints/src/methods/map_unwrap_or.rs +++ b/clippy_lints/src/methods/map_unwrap_or.rs @@ -1,8 +1,8 @@ -use crate::utils::meets_msrv; -use crate::utils::usage::mutated_variables; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::meets_msrv; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::usage::mutated_variables; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index af8fe7abd96..cbfb350ebb1 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -55,6 +55,10 @@ use bind_instead_of_map::BindInsteadOfMap; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{contains_ty, implements_trait, is_copy, is_type_diagnostic_item}; +use clippy_utils::{ + contains_return, get_trait_def_id, in_macro, iter_input_pats, match_def_path, match_qpath, method_calls, + method_chain_args, paths, return_ty, single_segment_path, SpanlessEq, +}; use if_chain::if_chain; use rustc_ast::ast; use rustc_errors::Applicability; @@ -68,11 +72,6 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::{sym, SymbolStr}; use rustc_typeck::hir_ty_to_ty; -use crate::utils::{ - contains_return, get_trait_def_id, in_macro, iter_input_pats, match_def_path, match_qpath, method_calls, - method_chain_args, paths, return_ty, single_segment_path, SpanlessEq, -}; - declare_clippy_lint! { /// **What it does:** Checks for `.unwrap()` calls on `Option`s and on `Result`s. /// diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index f921d7b16c0..d11ede080dc 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -1,7 +1,7 @@ -use crate::utils::{match_def_path, meets_msrv, path_to_local_id, paths, remove_blocks}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{match_def_path, meets_msrv, path_to_local_id, paths, remove_blocks}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index e8b057c2d74..d93db2c22e4 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -1,7 +1,7 @@ -use crate::utils::{match_qpath, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{match_qpath, paths}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index c6459648cd5..e252abc177a 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -1,5 +1,5 @@ -use crate::utils::differing_macro_contexts; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::differing_macro_contexts; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_copy; use clippy_utils::ty::is_type_diagnostic_item; diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 1b43802a08e..4880d13f39a 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -1,8 +1,8 @@ -use crate::utils::eager_or_lazy::is_lazyness_candidate; -use crate::utils::{contains_return, get_trait_def_id, last_path_segment, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::eager_or_lazy::is_lazyness_candidate; use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_macro_callsite}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type}; +use clippy_utils::{contains_return, get_trait_def_id, last_path_segment, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 18e1064b018..13546dc1779 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -1,7 +1,7 @@ -use crate::utils::{is_trait_method, strip_pat_refs}; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{is_trait_method, strip_pat_refs}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/skip_while_next.rs b/clippy_lints/src/methods/skip_while_next.rs index 8995226191b..3db83785b59 100644 --- a/clippy_lints/src/methods/skip_while_next.rs +++ b/clippy_lints/src/methods/skip_while_next.rs @@ -1,5 +1,5 @@ -use crate::utils::is_trait_method; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_trait_method; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index d9b97168490..52b26a36fe3 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -1,5 +1,5 @@ -use crate::utils::method_chain_args; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::method_chain_args; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index fd4651dd182..7015bd54c35 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -1,6 +1,6 @@ -use crate::utils::usage::mutated_variables; -use crate::utils::{expr_or_init, is_trait_method}; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::usage::mutated_variables; +use clippy_utils::{expr_or_init, is_trait_method}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/uninit_assumed_init.rs b/clippy_lints/src/methods/uninit_assumed_init.rs index 071856c3ba6..f2f6ef4be6c 100644 --- a/clippy_lints/src/methods/uninit_assumed_init.rs +++ b/clippy_lints/src/methods/uninit_assumed_init.rs @@ -1,5 +1,5 @@ -use crate::utils::{match_def_path, match_qpath, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{match_def_path, match_qpath, paths}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 670134c68f2..48d905ab833 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -1,14 +1,13 @@ -use crate::utils::usage::mutated_variables; -use crate::utils::{is_trait_method, match_qpath, path_to_local_id, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::usage::mutated_variables; +use clippy_utils::{is_trait_method, match_qpath, path_to_local_id, paths}; +use if_chain::if_chain; use rustc_hir as hir; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_lint::LateContext; use rustc_middle::hir::map::Map; use rustc_span::sym; -use if_chain::if_chain; - use super::UNNECESSARY_FILTER_MAP; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 3ccde57de3f..1268fd4bda9 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -1,6 +1,6 @@ -use crate::utils::{is_trait_method, path_to_local_id, remove_blocks, strip_pat_refs}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::{is_trait_method, path_to_local_id, remove_blocks, strip_pat_refs}; use if_chain::if_chain; use rustc_ast::ast; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 3874673bf9f..a86185bf0a6 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -1,7 +1,7 @@ -use crate::utils::{eager_or_lazy, usage}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{eager_or_lazy, usage}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index 13c95e33fef..b5505af0f7e 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -1,7 +1,7 @@ -use crate::utils::{get_parent_expr, match_trait_method, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::walk_ptrs_ty_depth; +use clippy_utils::{get_parent_expr, match_trait_method, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 6a4e70e50af..776f4c7b741 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -1,6 +1,6 @@ use crate::consts::{constant_simple, Constant}; -use crate::utils::{match_def_path, match_trait_method, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{match_def_path, match_trait_method, paths}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 03d07287005..026ea50936a 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -18,8 +18,8 @@ use rustc_span::source_map::{ExpnKind, Span}; use rustc_span::symbol::sym; use crate::consts::{constant, Constant}; -use crate::utils::sugg::Sugg; -use crate::utils::{ +use clippy_utils::sugg::Sugg; +use clippy_utils::{ get_item_name, get_parent_expr, higher, in_constant, is_diagnostic_assoc_item, is_integer_const, iter_input_pats, last_path_segment, match_qpath, unsext, SpanlessEq, }; diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index aba4accccb1..23554669d97 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -1,7 +1,7 @@ -use crate::utils::qualify_min_const_fn::is_min_const_fn; -use crate::utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, trait_ref_of_method}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::qualify_min_const_fn::is_min_const_fn; use clippy_utils::ty::has_drop; +use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, trait_ref_of_method}; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId}; diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index 1b00cf2c75d..6a52de4f713 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -1,6 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::sext; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sext; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 6eaeaebe781..584daa5e119 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -1,7 +1,7 @@ //! lint on multiple versions of a crate being used -use crate::utils::run_lints; use clippy_utils::diagnostics::span_lint; +use clippy_utils::run_lints; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::{Crate, CRATE_HIR_ID}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 39aec79734c..41bd07bcf1e 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -1,5 +1,5 @@ -use crate::utils::{match_def_path, paths, trait_ref_of_method}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{match_def_path, paths, trait_ref_of_method}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::TypeFoldable; diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index c11ccc94890..ef33e41a5fa 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -1,5 +1,5 @@ -use crate::utils::higher; use clippy_utils::diagnostics::span_lint; +use clippy_utils::higher; use rustc_hir as hir; use rustc_hir::intravisit; use rustc_lint::{LateContext, LateLintPass, LintContext}; diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index fb8895e08d0..533c5a22db0 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -1,5 +1,5 @@ -use crate::utils::{higher, is_direct_expn_of}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{higher, is_direct_expn_of}; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index c62ff7323f3..3e2b2782ed5 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -1,5 +1,5 @@ -use crate::utils::in_macro; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_macro; use if_chain::if_chain; use rustc_ast::ast::{BindingMode, Lifetime, Mutability, Param, PatKind, Path, TyKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 4c67304d23e..db7b3423ad9 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -2,10 +2,10 @@ //! //! This lint is **warn** by default -use crate::utils::sugg::Sugg; -use crate::utils::{is_expn_of, parent_node_is_if_expr}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::sugg::Sugg; +use clippy_utils::{is_expn_of, parent_node_is_if_expr}; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 72436b51dcb..79d84da2dfc 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -2,8 +2,8 @@ //! //! This lint is **warn** by default -use crate::utils::is_automatically_derived; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::is_automatically_derived; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index fc8ee6cb8ef..075bbf9a426 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -1,8 +1,8 @@ -use crate::utils::ptr::get_spans; -use crate::utils::{get_trait_def_id, is_self, paths}; use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; +use clippy_utils::ptr::get_spans; use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item}; +use clippy_utils::{get_trait_def_id, is_self, paths}; use if_chain::if_chain; use rustc_ast::ast::Attribute; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index ecf48d082af..99e85e6683c 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -1,6 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{is_ok_ctor, is_some_ctor, meets_msrv}; +use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Body, Expr, ExprKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -8,9 +10,6 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; -use crate::utils; -use if_chain::if_chain; - declare_clippy_lint! { /// **What it does:** /// Suggests alternatives for useless applications of `?` in terminating expressions @@ -161,7 +160,7 @@ fn is_some_or_ok_call<'a>( // Check outer expression matches CALL_IDENT(ARGUMENT) format if let ExprKind::Call(path, args) = &expr.kind; if let ExprKind::Path(QPath::Resolved(None, path)) = &path.kind; - if utils::is_some_ctor(cx, path.res) || utils::is_ok_ctor(cx, path.res); + if is_some_ctor(cx, path.res) || is_ok_ctor(cx, path.res); // Extract inner expression from ARGUMENT if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &args[0].kind; @@ -182,7 +181,7 @@ fn is_some_or_ok_call<'a>( let inner_is_some = is_type_diagnostic_item(cx, inner_ty, sym::option_type); // Check for Option MSRV - let meets_option_msrv = utils::meets_msrv(nqml.msrv.as_ref(), &NEEDLESS_QUESTION_MARK_OPTION_MSRV); + let meets_option_msrv = meets_msrv(nqml.msrv.as_ref(), &NEEDLESS_QUESTION_MARK_OPTION_MSRV); if outer_is_some && inner_is_some && meets_option_msrv { return Some(SomeOkCall::SomeCall(expr, inner_expr)); } @@ -196,7 +195,7 @@ fn is_some_or_ok_call<'a>( let does_not_call_from = !has_implicit_error_from(cx, expr, inner_expr); // Must meet Result MSRV - let meets_result_msrv = utils::meets_msrv(nqml.msrv.as_ref(), &NEEDLESS_QUESTION_MARK_RESULT_MSRV); + let meets_result_msrv = meets_msrv(nqml.msrv.as_ref(), &NEEDLESS_QUESTION_MARK_RESULT_MSRV); if outer_is_result && inner_is_result && does_not_call_from && meets_result_msrv { return Some(SomeOkCall::OkCall(expr, inner_expr)); } diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index e291885d34d..4b935c7b906 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -1,13 +1,12 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::implements_trait; +use clippy_utils::{self, get_trait_def_id, paths}; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::{self, paths}; - declare_clippy_lint! { /// **What it does:** /// Checks for the usage of negated comparison operators on types which only implement @@ -61,7 +60,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd { let ty = cx.typeck_results().expr_ty(left); let implements_ord = { - if let Some(id) = utils::get_trait_def_id(cx, &paths::ORD) { + if let Some(id) = get_trait_def_id(cx, &paths::ORD) { implements_trait(cx, ty, id, &[]) } else { return; diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 9fbb6b02742..502e5e4bf37 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -1,7 +1,7 @@ -use crate::utils::paths; -use crate::utils::sugg::DiagnosticBuilderExt; -use crate::utils::{get_trait_def_id, return_ty}; use clippy_utils::diagnostics::span_lint_hir_and_then; +use clippy_utils::paths; +use clippy_utils::sugg::DiagnosticBuilderExt; +use clippy_utils::{get_trait_def_id, return_ty}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 5db614497e3..b86ae1426ef 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -5,6 +5,8 @@ use std::ptr; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::in_constant; +use if_chain::if_chain; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{ @@ -19,9 +21,6 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{InnerSpan, Span, DUMMY_SP}; use rustc_typeck::hir_ty_to_ty; -use crate::utils::in_constant; -use if_chain::if_chain; - // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. declare_clippy_lint! { diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 8e8aaa67afa..c61dff4b8e0 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -1,5 +1,5 @@ -use crate::utils::paths; use clippy_utils::diagnostics::span_lint; +use clippy_utils::paths; use clippy_utils::ty::match_type; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index 343159f9ae2..a0bc324e026 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -1,5 +1,5 @@ -use crate::utils::is_direct_expn_of; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_direct_expn_of; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index eab08a58320..a76a4a33f1f 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -1,11 +1,10 @@ -use crate::utils; -use crate::utils::eager_or_lazy; -use crate::utils::paths; -use crate::utils::sugg::Sugg; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::paths; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::usage::contains_return_break_continue_macro; +use clippy_utils::{eager_or_lazy, get_enclosing_block, in_macro, match_qpath}; use if_chain::if_chain; - use rustc_errors::Applicability; use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, MatchSource, Mutability, PatKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; @@ -110,7 +109,7 @@ fn extract_body_from_arm<'a>(arm: &'a Arm<'a>) -> Option<&'a Expr<'a>> { /// If this is the else body of an if/else expression, then we need to wrap /// it in curly braces. Otherwise, we don't. fn should_wrap_in_braces(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - utils::get_enclosing_block(cx, expr.hir_id).map_or(false, |parent| { + get_enclosing_block(cx, expr.hir_id).map_or(false, |parent| { let mut should_wrap = false; if let Some(Expr { @@ -160,15 +159,15 @@ fn detect_option_if_let_else<'tcx>( expr: &'_ Expr<'tcx>, ) -> Option { if_chain! { - if !utils::in_macro(expr.span); // Don't lint macros, because it behaves weirdly + if !in_macro(expr.span); // Don't lint macros, because it behaves weirdly if let ExprKind::Match(cond_expr, arms, MatchSource::IfLetDesugar{contains_else_clause: true}) = &expr.kind; if arms.len() == 2; if !is_result_ok(cx, cond_expr); // Don't lint on Result::ok because a different lint does it already if let PatKind::TupleStruct(struct_qpath, &[inner_pat], _) = &arms[0].pat.kind; - if utils::match_qpath(struct_qpath, &paths::OPTION_SOME); + if match_qpath(struct_qpath, &paths::OPTION_SOME); if let PatKind::Binding(bind_annotation, _, id, _) = &inner_pat.kind; - if !utils::usage::contains_return_break_continue_macro(arms[0].body); - if !utils::usage::contains_return_break_continue_macro(arms[1].body); + if !contains_return_break_continue_macro(arms[0].body); + if !contains_return_break_continue_macro(arms[1].body); then { let capture_mut = if bind_annotation == &BindingAnnotation::Mutable { "mut " } else { "" }; let some_body = extract_body_from_arm(&arms[0])?; diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 524b96921fe..cf667c6e805 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -1,5 +1,5 @@ -use crate::utils::SpanlessEq; use clippy_utils::diagnostics::span_lint; +use clippy_utils::SpanlessEq; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 880951f3e3e..d32b937b209 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -1,6 +1,6 @@ -use crate::utils::{find_macro_calls, return_ty}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{find_macro_calls, return_ty}; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index ad4ed831941..d06e7f8fe1e 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -1,5 +1,5 @@ -use crate::utils::{is_expn_of, match_panic_call}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{is_expn_of, match_panic_call}; use if_chain::if_chain; use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 06985cef4ff..1251ddd9a02 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -1,5 +1,5 @@ -use crate::utils::is_automatically_derived; use clippy_utils::diagnostics::span_lint_hir; +use clippy_utils::is_automatically_derived; use if_chain::if_chain; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index c14273840c4..9a5b1c3b944 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -1,7 +1,7 @@ use std::cmp; -use crate::utils::is_self_ty; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_self_ty; use clippy_utils::source::snippet; use clippy_utils::ty::is_copy; use if_chain::if_chain; diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index dd63cf99e42..288e0e4586e 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -1,5 +1,5 @@ -use crate::utils::last_path_segment; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::last_path_segment; use rustc_hir::{ intravisit, Body, Expr, ExprKind, FieldPat, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatKind, QPath, Stmt, StmtKind, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 779eddcc170..be686b1b0cd 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -1,10 +1,10 @@ //! Checks for usage of `&Vec[_]` and `&String`. -use crate::utils::ptr::get_spans; -use crate::utils::{is_allowed, match_qpath, paths}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::ptr::get_spans; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{is_type_diagnostic_item, match_type, walk_ptrs_hir_ty}; +use clippy_utils::{is_allowed, match_qpath, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ diff --git a/clippy_lints/src/ptr_eq.rs b/clippy_lints/src/ptr_eq.rs index 82408c639b1..5796c59c8b3 100644 --- a/clippy_lints/src/ptr_eq.rs +++ b/clippy_lints/src/ptr_eq.rs @@ -1,5 +1,5 @@ -use crate::utils; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_macro; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_errors::Applicability; @@ -42,7 +42,7 @@ static LINT_MSG: &str = "use `std::ptr::eq` when comparing raw pointers"; impl LateLintPass<'_> for PtrEq { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if utils::in_macro(expr.span) { + if in_macro(expr.span) { return; } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index c4686623487..2054255a7c9 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -1,5 +1,8 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{eq_expr_value, match_def_path, match_qpath, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; @@ -8,10 +11,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -use crate::utils::sugg::Sugg; -use crate::utils::{eq_expr_value, match_def_path, match_qpath, paths}; -use clippy_utils::diagnostics::span_lint_and_sugg; - declare_clippy_lint! { /// **What it does:** Checks for expressions that could be replaced by the question mark operator. /// diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index d476d95256f..95b21489eb5 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -1,6 +1,9 @@ use crate::consts::{constant, Constant}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability}; +use clippy_utils::sugg::Sugg; +use clippy_utils::{get_parent_expr, in_constant, is_integer_const, meets_msrv, single_segment_path}; +use clippy_utils::{higher, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::RangeLimits; use rustc_errors::Applicability; @@ -14,10 +17,6 @@ use rustc_span::sym; use rustc_span::symbol::Ident; use std::cmp::Ordering; -use crate::utils::sugg::Sugg; -use crate::utils::{get_parent_expr, in_constant, is_integer_const, meets_msrv, single_segment_path}; -use crate::utils::{higher, SpanlessEq}; - declare_clippy_lint! { /// **What it does:** Checks for zipping a collection with the range of /// `0.._.len()`. diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 3d799328bb5..60da2bcb04a 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -1,7 +1,7 @@ -use crate::utils::{fn_has_unsatisfiable_preds, match_def_path, paths}; use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, walk_ptrs_ty_depth}; +use clippy_utils::{fn_has_unsatisfiable_preds, match_def_path, paths}; use if_chain::if_chain; use rustc_data_structures::{fx::FxHashMap, transitive_relation::TransitiveRelation}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index fd11150bce2..f77be6fdf04 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -1,5 +1,5 @@ -use crate::utils::meets_msrv; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::meets_msrv; use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index da8339a795a..32b57698ec5 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -1,5 +1,5 @@ -use crate::utils::meets_msrv; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::meets_msrv; use clippy_utils::source::snippet; use rustc_ast::ast::{Item, ItemKind, Ty, TyKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index 452fef0694f..0922cfa494e 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -1,5 +1,5 @@ -use crate::utils::last_path_segment; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::last_path_segment; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index ec2acb6a0ab..d6336389b0a 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -1,7 +1,7 @@ -use crate::utils::in_macro; -use crate::utils::sugg::Sugg; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_macro; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; +use clippy_utils::sugg::Sugg; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index bfa21ba9c97..1cc332de894 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -1,6 +1,6 @@ use crate::consts::{constant, Constant}; -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::{LitKind, StrStyle}; use rustc_data_structures::fx::FxHashSet; diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs index b39e9d5a78c..63e5ec69e66 100644 --- a/clippy_lints/src/repeat_once.rs +++ b/clippy_lints/src/repeat_once.rs @@ -1,6 +1,6 @@ use crate::consts::{constant_context, Constant}; -use crate::utils::in_macro; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_macro; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 59d3c0ca5f0..8995ae431ad 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -1,5 +1,6 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_opt; +use clippy_utils::{fn_def_id, in_macro, match_qpath}; use if_chain::if_chain; use rustc_ast::ast::Attribute; use rustc_errors::Applicability; @@ -13,8 +14,6 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::sym; -use crate::utils::{fn_def_id, in_macro, match_qpath}; - declare_clippy_lint! { /// **What it does:** Checks for `let`-bindings, which are subsequently /// returned. diff --git a/clippy_lints/src/self_assignment.rs b/clippy_lints/src/self_assignment.rs index 320d1a8dbe3..e7925c4fbde 100644 --- a/clippy_lints/src/self_assignment.rs +++ b/clippy_lints/src/self_assignment.rs @@ -1,5 +1,5 @@ -use crate::utils::eq_expr_value; use clippy_utils::diagnostics::span_lint; +use clippy_utils::eq_expr_value; use clippy_utils::source::snippet; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index e43947025b9..f61af15fbed 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -1,6 +1,6 @@ -use crate::utils::{in_macro, sugg}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_macro_callsite; +use clippy_utils::{in_macro, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Block, ExprKind}; diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 632715852c5..169f7d26285 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -1,5 +1,5 @@ -use crate::utils::{get_trait_def_id, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{get_trait_def_id, paths}; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 8ef58b6d563..612d2fd84cb 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -1,6 +1,6 @@ -use crate::utils::{contains_name, higher, iter_input_pats}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; +use clippy_utils::{contains_name, higher, iter_input_pats}; use rustc_hir::intravisit::FnKind; use rustc_hir::{ Block, Body, Expr, ExprKind, FnDecl, Guard, HirId, Local, MutTy, Pat, PatKind, Path, QPath, StmtKind, Ty, TyKind, diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 6d15a6c444e..c9d72aabb6a 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -1,5 +1,5 @@ -use crate::utils::in_macro; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_macro; use if_chain::if_chain; use rustc_ast::{Item, ItemKind, UseTreeKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index 8920d446b9c..09e00866815 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -1,8 +1,8 @@ //! Lint on use of `size_of` or `size_of_val` of T in an expression //! expecting a count of T -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_hir::BinOpKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 7f0f21084af..d55a83f1613 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -1,6 +1,6 @@ -use crate::utils::sugg::Sugg; -use crate::utils::{get_enclosing_block, match_qpath, SpanlessEq}; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg::Sugg; +use clippy_utils::{get_enclosing_block, match_qpath, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 85e4bb806e7..65790375c73 100644 --- a/clippy_lints/src/stable_sort_primitive.rs +++ b/clippy_lints/src/stable_sort_primitive.rs @@ -1,8 +1,6 @@ -use crate::utils::{is_slice_of_primitives, sugg::Sugg}; use clippy_utils::diagnostics::span_lint_and_then; - +use clippy_utils::{is_slice_of_primitives, sugg::Sugg}; use if_chain::if_chain; - use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 626166f9008..760f5e3b432 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -1,8 +1,8 @@ -use crate::utils::SpanlessEq; -use crate::utils::{get_parent_expr, is_allowed, match_function_call, method_calls, paths}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::SpanlessEq; +use clippy_utils::{get_parent_expr, is_allowed, match_function_call, method_calls, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, QPath}; diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 364c99adc69..1e5d3c17e3b 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -1,4 +1,4 @@ -use crate::utils::ast_utils::{eq_id, is_useless_with_eq_exprs, IdentIter}; +use clippy_utils::ast_utils::{eq_id, is_useless_with_eq_exprs, IdentIter}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use core::ops::{Add, AddAssign}; diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index ef14b6c5136..0f024c9a11e 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -1,5 +1,5 @@ -use crate::utils::{get_trait_def_id, trait_ref_of_method}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{get_trait_def_id, trait_ref_of_method}; use if_chain::if_chain; use rustc_hir as hir; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; @@ -159,7 +159,7 @@ fn check_binop( expected_ops: &[hir::BinOpKind], ) -> Option<&'static str> { let mut trait_ids = vec![]; - let [krate, module] = crate::utils::paths::OPS_MODULE; + let [krate, module] = clippy_utils::paths::OPS_MODULE; for &t in traits { let path = [krate, module, t]; diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 83fe3c49959..14519eaa962 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -1,8 +1,8 @@ -use crate::utils::sugg::Sugg; -use crate::utils::{differing_macro_contexts, eq_expr_value}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{differing_macro_contexts, eq_expr_value}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, StmtKind}; diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index 75a13cb9187..8ef25dc816c 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -1,5 +1,5 @@ -use crate::utils::is_adjusted; use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_adjusted; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index abc9b2fe88e..c66a596c784 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -1,5 +1,5 @@ -use crate::utils::match_def_path; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::match_def_path; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index 42605c01089..42ec14c31b5 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -1,5 +1,5 @@ -use crate::utils::{is_diagnostic_assoc_item, match_def_path, path_to_local_id, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{is_diagnostic_assoc_item, match_def_path, path_to_local_id, paths}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index cfcc8da9910..3ff27c3bcf4 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -1,6 +1,6 @@ -use crate::utils::{in_macro, SpanlessHash}; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::{snippet, snippet_with_applicability}; +use clippy_utils::{in_macro, SpanlessHash}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index c1870f5208b..47d58bd30db 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -12,7 +12,7 @@ mod useless_transmute; mod utils; mod wrong_transmute; -use crate::utils::{in_constant, match_def_path, paths}; +use clippy_utils::{in_constant, match_def_path, paths}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/transmute/transmute_float_to_int.rs b/clippy_lints/src/transmute/transmute_float_to_int.rs index f61b5362b5a..72489f27cd3 100644 --- a/clippy_lints/src/transmute/transmute_float_to_int.rs +++ b/clippy_lints/src/transmute/transmute_float_to_int.rs @@ -1,6 +1,6 @@ use super::TRANSMUTE_FLOAT_TO_INT; -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use if_chain::if_chain; use rustc_ast as ast; use rustc_errors::Applicability; diff --git a/clippy_lints/src/transmute/transmute_int_to_bool.rs b/clippy_lints/src/transmute/transmute_int_to_bool.rs index ebdd1eba744..cc0a5643e2a 100644 --- a/clippy_lints/src/transmute/transmute_int_to_bool.rs +++ b/clippy_lints/src/transmute/transmute_int_to_bool.rs @@ -1,6 +1,6 @@ use super::TRANSMUTE_INT_TO_BOOL; -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use rustc_ast as ast; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/transmute/transmute_int_to_char.rs b/clippy_lints/src/transmute/transmute_int_to_char.rs index afecfc3d701..8f884e6a4a1 100644 --- a/clippy_lints/src/transmute/transmute_int_to_char.rs +++ b/clippy_lints/src/transmute/transmute_int_to_char.rs @@ -1,6 +1,6 @@ use super::TRANSMUTE_INT_TO_CHAR; -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use rustc_ast as ast; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/transmute/transmute_int_to_float.rs b/clippy_lints/src/transmute/transmute_int_to_float.rs index c762a7ab885..2b6a4cff81e 100644 --- a/clippy_lints/src/transmute/transmute_int_to_float.rs +++ b/clippy_lints/src/transmute/transmute_int_to_float.rs @@ -1,6 +1,6 @@ use super::TRANSMUTE_INT_TO_FLOAT; -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index 820c56a215e..7b646bfc0c6 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -1,6 +1,6 @@ use super::TRANSMUTE_PTR_TO_PTR; -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index 049210e555c..f14eef93645 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -1,7 +1,7 @@ use super::utils::get_type_snippet; use super::TRANSMUTE_PTR_TO_REF; -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability, QPath}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index 993ef8698f8..d105e37abf9 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -1,7 +1,7 @@ use super::{TRANSMUTE_BYTES_TO_STR, TRANSMUTE_PTR_TO_PTR}; -use crate::utils::sugg; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet; +use clippy_utils::sugg; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability}; diff --git a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs index da7d1016d97..e2c6d130f3c 100644 --- a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs +++ b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs @@ -1,7 +1,7 @@ use super::utils::can_be_expressed_as_pointer_cast; use super::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS; -use crate::utils::sugg; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/unsound_collection_transmute.rs b/clippy_lints/src/transmute/unsound_collection_transmute.rs index 9bea88be7da..de9277e016e 100644 --- a/clippy_lints/src/transmute/unsound_collection_transmute.rs +++ b/clippy_lints/src/transmute/unsound_collection_transmute.rs @@ -1,7 +1,7 @@ use super::utils::is_layout_incompatible; use super::UNSOUND_COLLECTION_TRANSMUTE; -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{match_def_path, paths}; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 29ffe03b673..445bcf60fa7 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -1,6 +1,6 @@ use super::USELESS_TRANSMUTE; -use crate::utils::sugg; use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; +use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 0633697687a..c6d0d63b0b5 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -1,4 +1,4 @@ -use crate::utils::last_path_segment; +use clippy_utils::last_path_segment; use clippy_utils::source::snippet; use clippy_utils::ty::is_normalizable; use if_chain::if_chain; diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 3a2b1359a54..d42cdde110e 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -1,6 +1,6 @@ use crate::consts::{constant_context, Constant}; -use crate::utils::{match_qpath, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{match_qpath, paths}; use if_chain::if_chain; use rustc_ast::LitKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 1fce03b4f47..e61058c2749 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -1,7 +1,7 @@ -use crate::utils::{differing_macro_contexts, in_macro, match_def_path, match_qpath, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet, snippet_with_macro_callsite}; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{differing_macro_contexts, in_macro, match_def_path, match_qpath, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem, MatchSource, QPath}; diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index eab81b1e246..1721fcfdcf4 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -1,6 +1,6 @@ -use crate::utils::{match_path, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; +use clippy_utils::{match_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ diff --git a/clippy_lints/src/types/box_vec.rs b/clippy_lints/src/types/box_vec.rs index 6d04a47a5c8..d8b1953457c 100644 --- a/clippy_lints/src/types/box_vec.rs +++ b/clippy_lints/src/types/box_vec.rs @@ -1,10 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_ty_param_diagnostic_item; use rustc_hir::{self as hir, def_id::DefId, QPath}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::is_ty_param_diagnostic_item; - use super::BOX_VEC; pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { diff --git a/clippy_lints/src/types/linked_list.rs b/clippy_lints/src/types/linked_list.rs index e9e1995f6a5..a9fbe7aa315 100644 --- a/clippy_lints/src/types/linked_list.rs +++ b/clippy_lints/src/types/linked_list.rs @@ -1,9 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::{match_def_path, paths}; use rustc_hir::{self as hir, def_id::DefId}; use rustc_lint::LateContext; -use crate::utils::{match_def_path, paths}; - use super::LINKEDLIST; pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, def_id: DefId) -> bool { diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 5103a259559..c0cd48e94b2 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -36,8 +36,8 @@ use rustc_target::spec::abi::Abi; use rustc_typeck::hir_ty_to_ty; use crate::consts::{constant, Constant}; -use crate::utils::paths; -use crate::utils::{clip, comparisons, differing_macro_contexts, int_bits, match_path, sext, unsext}; +use clippy_utils::paths; +use clippy_utils::{clip, comparisons, differing_macro_contexts, int_bits, match_path, sext, unsext}; declare_clippy_lint! { /// **What it does:** Checks for use of `Box>` anywhere in the code. @@ -618,7 +618,7 @@ fn detect_absurd_comparison<'tcx>( ) -> Option<(ExtremeExpr<'tcx>, AbsurdComparisonResult)> { use crate::types::AbsurdComparisonResult::{AlwaysFalse, AlwaysTrue, InequalityImpossible}; use crate::types::ExtremeType::{Maximum, Minimum}; - use crate::utils::comparisons::{normalize_comparison, Rel}; + use clippy_utils::comparisons::{normalize_comparison, Rel}; // absurd comparison only makes sense on primitive types // primitive types don't implement comparison operators with each other @@ -860,7 +860,7 @@ fn upcast_comparison_bounds_err<'tcx>( rhs: &'tcx Expr<'_>, invert: bool, ) { - use crate::utils::comparisons::Rel; + use clippy_utils::comparisons::Rel; if let Some((lb, ub)) = lhs_bounds { if let Some(norm_rhs_val) = node_as_const_fullint(cx, rhs) { diff --git a/clippy_lints/src/types/option_option.rs b/clippy_lints/src/types/option_option.rs index 79c5a32de2c..b2692c48076 100644 --- a/clippy_lints/src/types/option_option.rs +++ b/clippy_lints/src/types/option_option.rs @@ -1,10 +1,9 @@ use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_ty_param_diagnostic_item; use rustc_hir::{self as hir, def_id::DefId, QPath}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::is_ty_param_diagnostic_item; - use super::OPTION_OPTION; pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { diff --git a/clippy_lints/src/types/rc_buffer.rs b/clippy_lints/src/types/rc_buffer.rs index d5fc23f2e39..ef629a35d10 100644 --- a/clippy_lints/src/types/rc_buffer.rs +++ b/clippy_lints/src/types/rc_buffer.rs @@ -1,12 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item}; use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item}; - use super::RC_BUFFER; pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index 71c014f96f7..c0c1f340583 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -1,12 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; +use clippy_utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item, is_ty_param_lang_item}; use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, LangItem, QPath, TyKind}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use crate::utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item, is_ty_param_lang_item}; - use super::{utils, REDUNDANT_ALLOCATION}; pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { diff --git a/clippy_lints/src/types/utils.rs b/clippy_lints/src/types/utils.rs index 4d64748f998..45f891ed718 100644 --- a/clippy_lints/src/types/utils.rs +++ b/clippy_lints/src/types/utils.rs @@ -1,11 +1,9 @@ +use clippy_utils::last_path_segment; +use if_chain::if_chain; use rustc_hir::{GenericArg, QPath, TyKind}; use rustc_lint::LateContext; use rustc_span::source_map::Span; -use crate::utils::last_path_segment; - -use if_chain::if_chain; - pub(super) fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option { let last = last_path_segment(qpath); if_chain! { diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index 8cedb0ede2b..d2c373db261 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::last_path_segment; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; @@ -9,8 +10,6 @@ use rustc_span::symbol::sym; use rustc_target::abi::LayoutOf; use rustc_typeck::hir_ty_to_ty; -use crate::utils::last_path_segment; - use super::VEC_BOX; pub(super) fn check( diff --git a/clippy_lints/src/undropped_manually_drops.rs b/clippy_lints/src/undropped_manually_drops.rs index 943573a2b53..b6749069176 100644 --- a/clippy_lints/src/undropped_manually_drops.rs +++ b/clippy_lints/src/undropped_manually_drops.rs @@ -1,6 +1,6 @@ -use crate::utils::{match_function_call, paths}; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_type_lang_item; +use clippy_utils::{match_function_call, paths}; use rustc_hir::{lang_items, Expr}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index c37bbf297f8..d81e31f5a21 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -1,5 +1,5 @@ -use crate::utils::is_allowed; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_allowed; use clippy_utils::source::snippet; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index d0456347f8a..bad3e488bb6 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -1,5 +1,5 @@ -use crate::utils::{get_trait_def_id, paths}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; +use clippy_utils::{get_trait_def_id, paths}; use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, StmtKind}; diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 55715cc6bf3..8698a718bbd 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -1,12 +1,11 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::higher; +use clippy_utils::source::snippet_with_macro_callsite; use rustc_errors::Applicability; use rustc_hir::{Stmt, StmtKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; -use crate::utils::diagnostics::span_lint_and_then; -use crate::utils::higher; -use crate::utils::source::snippet_with_macro_callsite; - use super::LET_UNIT_VALUE; pub(super) fn check(cx: &LateContext<'_>, stmt: &Stmt<'_>) { diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index d4ef645fc8d..925ab577099 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -1,12 +1,10 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt}; +use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{self as hir, Block, Expr, ExprKind, MatchSource, Node, StmtKind}; use rustc_lint::LateContext; -use if_chain::if_chain; - -use crate::utils::diagnostics::span_lint_and_then; -use crate::utils::source::{indent_of, reindent_multiline, snippet_opt}; - use super::{utils, UNIT_ARG}; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { diff --git a/clippy_lints/src/unit_types/unit_cmp.rs b/clippy_lints/src/unit_types/unit_cmp.rs index f9c0374c86d..b3077dec5d8 100644 --- a/clippy_lints/src/unit_types/unit_cmp.rs +++ b/clippy_lints/src/unit_types/unit_cmp.rs @@ -1,9 +1,8 @@ +use clippy_utils::diagnostics::span_lint; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_span::hygiene::{ExpnKind, MacroKind}; -use crate::utils::diagnostics::span_lint; - use super::UNIT_CMP; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 2c51a8556d9..d5bc3de6698 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -1,5 +1,5 @@ -use crate::utils::{match_def_path, paths}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index aa83f6a74be..e23bab5eba0 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -1,5 +1,5 @@ -use crate::utils::sugg::Sugg; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index cb20192b683..9e227164695 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -1,6 +1,6 @@ -use crate::utils::{contains_return, in_macro, match_qpath, paths, return_ty, visitors::find_all_ret_expressions}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; +use clippy_utils::{contains_return, in_macro, match_qpath, paths, return_ty, visitors::find_all_ret_expressions}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 42ff1809ff4..512d505dfb5 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -1,8 +1,8 @@ #![allow(clippy::wildcard_imports, clippy::enum_glob_use)] -use crate::utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path}; -use crate::utils::over; +use clippy_utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path}; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::over; use rustc_ast::mut_visit::*; use rustc_ast::ptr::P; use rustc_ast::{self as ast, Pat, PatKind, PatKind::*, DUMMY_NODE_ID}; diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 31fd61f99f2..9990052e114 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -1,5 +1,5 @@ -use crate::utils::{is_try, match_trait_method, paths}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::{is_try, match_trait_method, paths}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 4642bf07c45..aef4ce75915 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -1,11 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::visitors::LocalUsedVisitor; use if_chain::if_chain; use rustc_hir::{Impl, ImplItem, ImplItemKind, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::visitors::LocalUsedVisitor; - declare_clippy_lint! { /// **What it does:** Checks methods that contain a `self` argument but don't use it /// diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index c45b851211c..329ea49024b 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::position_before_rarrow; use if_chain::if_chain; use rustc_ast::ast; @@ -8,8 +9,6 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::BytePos; -use clippy_utils::diagnostics::span_lint_and_sugg; - declare_clippy_lint! { /// **What it does:** Checks for unit (`()`) expressions that can be removed. /// diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 75b2f2da602..fb29acca18a 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -1,6 +1,6 @@ -use crate::utils::{differing_macro_contexts, usage::is_potentially_mutated}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{differing_macro_contexts, usage::is_potentially_mutated}; use if_chain::if_chain; use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Path, QPath, UnOp}; diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index a85f3ce5c9c..0d745813beb 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -1,6 +1,6 @@ -use crate::utils::{method_chain_args, return_ty}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{method_chain_args, return_ty}; use if_chain::if_chain; use rustc_hir as hir; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 9a42c833470..116cb8b1e1c 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -1,6 +1,6 @@ -use crate::utils::{in_macro, meets_msrv}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; +use clippy_utils::{in_macro, meets_msrv}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 1eb152daac8..3e1b69e676b 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -1,8 +1,8 @@ -use crate::utils::sugg::Sugg; -use crate::utils::{get_parent_expr, match_def_path, match_trait_method, paths}; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_macro_callsite}; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{get_parent_expr, match_def_path, match_trait_method, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, HirId, MatchSource}; diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 3dd190ba440..2de5b1a628e 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -1,7 +1,7 @@ //! A group of attributes that can be attached to Rust code in order //! to generate a clippy lint detecting said code automatically. -use crate::utils::get_attr; +use clippy_utils::get_attr; use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_ast::walk_list; use rustc_data_structures::fx::FxHashMap; diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 9e3973e1d51..191ff6e4f16 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -1,6 +1,6 @@ //! checks for attributes -use crate::utils::get_attr; +use clippy_utils::get_attr; use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index a566362ae78..c496ff1fb24 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,9 +1,8 @@ use crate::consts::{constant_simple, Constant}; -use crate::utils::{is_expn_of, match_def_path, match_qpath, method_calls, path_to_res, paths, run_lints, SpanlessEq}; - use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::snippet; use clippy_utils::ty::match_type; +use clippy_utils::{is_expn_of, match_def_path, match_qpath, method_calls, path_to_res, paths, run_lints, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, ModKind, NodeId}; use rustc_ast::visit::FnKind; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index be9a07f8d7c..d8b31344e6d 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -3,5 +3,3 @@ pub mod conf; pub mod inspector; #[cfg(feature = "internal-lints")] pub mod internal_lints; - -pub use clippy_utils::*; diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 9e142413365..1af9583887f 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -1,7 +1,7 @@ use crate::consts::{constant, Constant}; use crate::rustc_target::abi::LayoutOf; -use crate::utils::higher; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_copy; use if_chain::if_chain; diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 3ef55a82a17..8b696ed1c84 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -1,7 +1,7 @@ -use crate::utils::{match_def_path, path_to_local, path_to_local_id, paths}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{match_def_path, path_to_local, path_to_local_id, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index 9a2fb1414a1..e035d3c5cad 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -1,15 +1,14 @@ use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; +use rustc_ast::LitKind; use rustc_errors::Applicability; +use rustc_hir as hir; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; -use crate::utils::{match_def_path, paths}; -use rustc_ast::LitKind; -use rustc_hir as hir; - declare_clippy_lint! { /// **What it does:** Finds occurrences of `Vec::resize(0, an_int)` /// diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index 01dc54dc5fd..ec209b30951 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -1,5 +1,5 @@ -use crate::utils::paths; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::paths; use clippy_utils::ty::match_type; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, QPath}; diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index 8f96b962279..60c3489a449 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,5 +1,5 @@ -use crate::utils::run_lints; use clippy_utils::diagnostics::span_lint; +use clippy_utils::run_lints; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 424ca2a4c2f..51c1117d206 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -1,5 +1,5 @@ -use crate::utils::in_macro; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::in_macro; use clippy_utils::source::{snippet, snippet_with_applicability}; use if_chain::if_chain; use rustc_errors::Applicability; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 82466da6862..2abd033e2a0 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::paths; use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item, match_type}; use if_chain::if_chain; use rustc_hir::{self as hir, HirId, ItemKind, Node}; @@ -9,8 +10,6 @@ use rustc_span::sym; use rustc_target::abi::LayoutOf as _; use rustc_typeck::hir_ty_to_ty; -use crate::utils::paths; - declare_clippy_lint! { /// **What it does:** Checks for maps with zero-sized value types anywhere in the code. /// -- cgit 1.4.1-3-g733a5 From cadad20da1e970e62ea28f32a2f4a9177e8ca859 Mon Sep 17 00:00:00 2001 From: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> Date: Tue, 25 May 2021 00:54:50 +0000 Subject: Add semicolons up to `needless_for_each.rs` --- clippy_lints/src/assertions_on_constants.rs | 2 +- clippy_lints/src/attrs.rs | 6 +++--- clippy_lints/src/bit_mask.rs | 6 +++--- clippy_lints/src/booleans.rs | 6 +++--- clippy_lints/src/collapsible_if.rs | 2 +- clippy_lints/src/comparison_chain.rs | 2 +- clippy_lints/src/copies.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 4 ++-- clippy_lints/src/double_comparison.rs | 8 ++++---- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/eq_op.rs | 12 ++++++------ clippy_lints/src/eta_reduction.rs | 7 ++++--- clippy_lints/src/eval_order_dependence.rs | 2 +- clippy_lints/src/functions/must_use.rs | 2 +- clippy_lints/src/functions/too_many_lines.rs | 2 +- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/implicit_return.rs | 2 +- clippy_lints/src/infinite_iter.rs | 2 +- clippy_lints/src/invalid_upcast_comparisons.rs | 4 ++-- clippy_lints/src/len_zero.rs | 4 ++-- clippy_lints/src/let_underscore.rs | 8 ++++---- clippy_lints/src/lifetimes.rs | 4 ++-- clippy_lints/src/literal_representation.rs | 8 ++++---- clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 8 ++++---- clippy_lints/src/loops/same_item_push.rs | 4 ++-- clippy_lints/src/loops/utils.rs | 8 ++++---- clippy_lints/src/macro_use.rs | 6 +++--- clippy_lints/src/manual_strip.rs | 2 +- clippy_lints/src/map_clone.rs | 6 +++--- clippy_lints/src/matches.rs | 10 +++++----- clippy_lints/src/methods/bind_instead_of_map.rs | 2 +- clippy_lints/src/methods/cloned_instead_of_copied.rs | 2 +- clippy_lints/src/methods/flat_map_option.rs | 2 +- clippy_lints/src/methods/mod.rs | 8 ++++---- clippy_lints/src/methods/unnecessary_fold.rs | 2 +- clippy_lints/src/misc_early/mod.rs | 10 +++++----- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/mutable_debug_assertion.rs | 2 +- clippy_lints/src/needless_arbitrary_self_type.rs | 4 ++-- clippy_lints/src/needless_bool.rs | 18 +++++++++--------- clippy_lints/src/needless_borrow.rs | 2 +- clippy_lints/src/needless_for_each.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 4 ++-- .../src/utils/internal_lints/metadata_collector.rs | 2 +- 46 files changed, 105 insertions(+), 104 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index c565e29d078..6c9ceaa45c2 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { &format!("`assert!(false, {})` should probably be replaced", panic_message), None, &format!("use `panic!({})` or `unreachable!({})`", panic_message, panic_message), - ) + ); }; if let Some(debug_assert_span) = is_expn_of(e.span, "debug_assert") { diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index c5b01461c1c..932cd58bf62 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -273,7 +273,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); if is_relevant_item(cx, item) { - check_attrs(cx, item.span, item.ident.name, attrs) + check_attrs(cx, item.span, item.ident.name, attrs); } match item.kind { ItemKind::ExternCrate(..) | ItemKind::Use(..) => { @@ -343,13 +343,13 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if is_relevant_impl(cx, item) { - check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())) + check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())); } } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { if is_relevant_trait(cx, item) { - check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())) + check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())); } } } diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index f7daf3dab49..0ac6dc28e73 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -115,9 +115,9 @@ impl<'tcx> LateLintPass<'tcx> for BitMask { if let ExprKind::Binary(cmp, left, right) = &e.kind { if cmp.node.is_comparison() { if let Some(cmp_opt) = fetch_int_literal(cx, right) { - check_compare(cx, left, cmp.node, cmp_opt, e.span) + check_compare(cx, left, cmp.node, cmp_opt, e.span); } else if let Some(cmp_val) = fetch_int_literal(cx, left) { - check_compare(cx, right, invert_cmp(cmp.node), cmp_val, e.span) + check_compare(cx, right, invert_cmp(cmp.node), cmp_val, e.span); } } } @@ -171,7 +171,7 @@ fn check_compare(cx: &LateContext<'_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp } fetch_int_literal(cx, right) .or_else(|| fetch_int_literal(cx, left)) - .map_or((), |mask| check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span)) + .map_or((), |mask| check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span)); } } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 67f0e0c7870..e72399af232 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool { _: Span, _: HirId, ) { - NonminimalBoolVisitor { cx }.visit_body(body) + NonminimalBoolVisitor { cx }.visit_body(body); } } @@ -184,7 +184,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { Term(n) => { let terminal = self.terminals[n as usize]; if let Some(str) = simplify_not(self.cx, terminal) { - self.output.push_str(&str) + self.output.push_str(&str); } else { self.output.push('!'); let snip = snippet_opt(self.cx, terminal.span)?; @@ -452,7 +452,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { } match &e.kind { ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => { - self.bool_expr(e) + self.bool_expr(e); }, ExprKind::Unary(UnOp::Not, inner) => { if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() { diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index dae5c86bd44..6e950738239 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -92,7 +92,7 @@ declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF, COLLAPSIBLE_ELSE_IF]); impl EarlyLintPass for CollapsibleIf { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { if !expr.span.from_expansion() { - check_if(cx, expr) + check_if(cx, expr); } } } diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 2a61d58e653..b6999bef6e7 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain { "`if` chain can be rewritten with `match`", None, "consider rewriting the `if` chain to use `cmp` and `match`", - ) + ); } } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index f956d171bfb..376a14b8181 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -476,7 +476,7 @@ fn emit_branches_sharing_code_lint( } suggestions.push(("end", span, suggestion.to_string())); - add_expr_note = !cx.typeck_results().expr_ty(if_expr).is_unit() + add_expr_note = !cx.typeck_results().expr_ty(if_expr).is_unit(); } let add_optional_msgs = |diag: &mut DiagnosticBuilder<'_>| { diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 6e883942680..759f7d4062d 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -181,9 +181,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { match stmt.kind { StmtKind::Local(local) => { if local.ty.is_some() { - self.ty_bounds.push(TyBound::Any) + self.ty_bounds.push(TyBound::Any); } else { - self.ty_bounds.push(TyBound::Nothing) + self.ty_bounds.push(TyBound::Nothing); } }, diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 58543ae6e4e..4966638cb1b 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -70,16 +70,16 @@ impl<'tcx> DoubleComparisons { #[rustfmt::skip] match (op, lkind, rkind) { (BinOpKind::Or, BinOpKind::Eq, BinOpKind::Lt) | (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Eq) => { - lint_double_comparison!(<=) + lint_double_comparison!(<=); }, (BinOpKind::Or, BinOpKind::Eq, BinOpKind::Gt) | (BinOpKind::Or, BinOpKind::Gt, BinOpKind::Eq) => { - lint_double_comparison!(>=) + lint_double_comparison!(>=); }, (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Gt) | (BinOpKind::Or, BinOpKind::Gt, BinOpKind::Lt) => { - lint_double_comparison!(!=) + lint_double_comparison!(!=); }, (BinOpKind::And, BinOpKind::Le, BinOpKind::Ge) | (BinOpKind::And, BinOpKind::Ge, BinOpKind::Le) => { - lint_double_comparison!(==) + lint_double_comparison!(==); }, _ => (), }; diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 8db5050a5ac..2eb8b1422ed 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -469,7 +469,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { let mut is_map_used = self.is_map_used; for arm in arms { if let Some(Guard::If(guard) | Guard::IfLet(_, guard)) = arm.guard { - self.visit_non_tail_expr(guard) + self.visit_non_tail_expr(guard); } is_map_used |= self.visit_cond_arm(arm.body); } diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 90f391b5f5c..47fe4e0de0d 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { vec![(left.span, lsnip), (right.span, rsnip)], ); }, - ) + ); } else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.typeck_results().expr_ty(right).into()]) @@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { Applicability::MaybeIncorrect, // FIXME #2597 ); }, - ) + ); } else if !lcpy && rcpy && implements_trait(cx, cx.typeck_results().expr_ty(left), trait_id, &[rty.into()]) @@ -194,7 +194,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { Applicability::MaybeIncorrect, // FIXME #2597 ); }, - ) + ); } }, // &foo == bar @@ -218,9 +218,9 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { Applicability::MaybeIncorrect, // FIXME #2597 ); }, - ) + ); } - }, + }, // foo == &bar (_, &ExprKind::AddrOf(BorrowKind::Ref, _, r)) => { let rty = cx.typeck_results().expr_ty(r); @@ -236,7 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { rsnip, Applicability::MaybeIncorrect, // FIXME #2597 ); - }) + }); } }, _ => {}, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index afc5d546474..8d066f305ee 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { for arg in args { // skip `foo(macro!())` if arg.span.ctxt() == expr.span.ctxt() { - check_closure(cx, arg) + check_closure(cx, arg); } } }, @@ -190,9 +190,10 @@ fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_a cx.tcx.impl_of_method(method_def_id).and_then(|_| { //a type may implicitly implement other type's methods (e.g. Deref) if match_types(expected_type_of_self, actual_type_of_self) { - return Some(get_type_name(cx, actual_type_of_self)); + Some(get_type_name(cx, actual_type_of_self)) + } else { + None } - None }) } diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 41acf55dd7d..5fdf5bc9e9d 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { self.visit_expr(e); for arm in arms { if let Some(Guard::If(if_expr)) = arm.guard { - self.visit_expr(if_expr) + self.visit_expr(if_expr); } // make sure top level arm expressions aren't linted self.maybe_walk_expr(&*arm.body); diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 20288427b4a..7f4fb68cf2f 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -240,7 +240,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { } }, Assign(target, ..) | AssignOp(_, target, _) | AddrOf(_, hir::Mutability::Mut, target) => { - self.mutates_static |= is_mutated_static(target) + self.mutates_static |= is_mutated_static(target); }, _ => {}, } diff --git a/clippy_lints/src/functions/too_many_lines.rs b/clippy_lints/src/functions/too_many_lines.rs index aa5494d5a7d..c02c343dc58 100644 --- a/clippy_lints/src/functions/too_many_lines.rs +++ b/clippy_lints/src/functions/too_many_lines.rs @@ -63,6 +63,6 @@ pub(super) fn check_fn(cx: &LateContext<'_>, span: Span, body: &'tcx hir::Body<' "this function has too many lines ({}/{})", line_count, too_many_lines_threshold ), - ) + ); } } diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 04730ace887..515b8887453 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { )); } } - }) + }); }, ); } diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 260a8f50157..f2f830ca5c0 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -67,7 +67,7 @@ fn lint_break(cx: &LateContext<'_>, break_span: Span, expr_span: Span) { "change `break` to `return` as shown", format!("return {}", snip), app, - ) + ); } #[derive(Clone, Copy, PartialEq, Eq)] diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index afee20ce43e..6b887da2630 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for InfiniteIter { return; }, }; - span_lint(cx, lint, expr.span, msg) + span_lint(cx, lint, expr.span, msg); } } diff --git a/clippy_lints/src/invalid_upcast_comparisons.rs b/clippy_lints/src/invalid_upcast_comparisons.rs index c67c02eefa5..aafdebef248 100644 --- a/clippy_lints/src/invalid_upcast_comparisons.rs +++ b/clippy_lints/src/invalid_upcast_comparisons.rs @@ -177,7 +177,7 @@ fn upcast_comparison_bounds_err<'tcx>( }, Rel::Eq | Rel::Ne => unreachable!(), } { - err_upcast_comparison(cx, span, lhs, true) + err_upcast_comparison(cx, span, lhs, true); } else if match rel { Rel::Lt => { if invert { @@ -195,7 +195,7 @@ fn upcast_comparison_bounds_err<'tcx>( }, Rel::Eq | Rel::Ne => unreachable!(), } { - err_upcast_comparison(cx, span, lhs, false) + err_upcast_comparison(cx, span, lhs, false); } } } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index bb57adff7be..583514b22f9 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -380,9 +380,9 @@ fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_> } } - check_len(cx, span, method_path.ident.name, args, &lit.node, op, compare_to) + check_len(cx, span, method_path.ident.name, args, &lit.node, op, compare_to); } else { - check_empty_expr(cx, span, method, lit, op) + check_empty_expr(cx, span, method, lit, op); } } diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 17e23781db7..e627b1385bc 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { None, "consider using an underscore-prefixed named \ binding or dropping explicitly with `std::mem::drop`" - ) + ); } else if init_ty.needs_drop(cx.tcx, cx.param_env) { span_lint_and_help( cx, @@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { None, "consider using an underscore-prefixed named \ binding or dropping explicitly with `std::mem::drop`" - ) + ); } else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) { span_lint_and_help( cx, @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { "non-binding let on an expression with `#[must_use]` type", None, "consider explicitly using expression value" - ) + ); } else if is_must_use_func_call(cx, init) { span_lint_and_help( cx, @@ -163,7 +163,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { "non-binding let on a result of a `#[must_use]` function", None, "consider explicitly using function result" - ) + ); } } } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 116ad072837..5ae68ba5b2f 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -205,7 +205,7 @@ fn could_use_elision<'tcx>( output_visitor.visit_ty(ty); } for lt in named_generics { - input_visitor.visit_generic_param(lt) + input_visitor.visit_generic_param(lt); } if input_visitor.abort() || output_visitor.abort() { @@ -463,7 +463,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker { // `'b` in `'a: 'b` is useless unless used elsewhere in // a non-lifetime bound if let GenericParamKind::Type { .. } = param.kind { - walk_generic_param(self, param) + walk_generic_param(self, param); } } fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index e93b2e36b86..e0c5578bd60 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -231,7 +231,7 @@ impl EarlyLintPass for LiteralDigitGrouping { } if let ExprKind::Lit(ref lit) = expr.kind { - self.check_lit(cx, lit) + self.check_lit(cx, lit); } } } @@ -294,7 +294,7 @@ impl LiteralDigitGrouping { } }; if should_warn { - warning_type.display(num_lit.format(), cx, lit.span) + warning_type.display(num_lit.format(), cx, lit.span); } } } @@ -424,7 +424,7 @@ impl EarlyLintPass for DecimalLiteralRepresentation { } if let ExprKind::Lit(ref lit) = expr.kind { - self.check_lit(cx, lit) + self.check_lit(cx, lit); } } } @@ -446,7 +446,7 @@ impl DecimalLiteralRepresentation { let hex = format!("{:#X}", val); let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false); let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| { - warning_type.display(num_lit.format(), cx, lit.span) + warning_type.display(num_lit.format(), cx, lit.span); }); } } diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index ce02ad013be..f0327b5d777 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -43,7 +43,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, m "to write this more concisely, try", format!("&{}{}", muta, object), applicability, - ) + ); } /// Returns `true` if the type of expr is one that provides `IntoIterator` impls diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 1425d50f560..d07b5a93b67 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -88,10 +88,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { if let ty::BorrowKind::MutBorrow = bk { if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low { - self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)) + self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)); } if Some(id) == self.hir_id_high { - self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)) + self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)); } } } @@ -100,10 +100,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low { - self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)) + self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)); } if Some(id) == self.hir_id_high { - self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)) + self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)); } } } diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index cb2c83e9029..f2e0a0f7003 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -32,10 +32,10 @@ pub(super) fn check<'tcx>( "it looks like the same item is being pushed into this Vec", None, &format!( - "try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})", + "try using vec![{}; SIZE] or {}.resize(NEW_SIZE, {})", item_str, vec_str, item_str ), - ) + ); } if !matches!(pat.kind, PatKind::Wild) { diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 4db6644b9d7..2f7360210ba 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -80,10 +80,10 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { } }, ExprKind::Assign(lhs, _, _) if lhs.hir_id == expr.hir_id => { - *state = IncrementVisitorVarState::DontWarn + *state = IncrementVisitorVarState::DontWarn; }, ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => { - *state = IncrementVisitorVarState::DontWarn + *state = IncrementVisitorVarState::DontWarn; }, _ => (), } @@ -207,7 +207,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { } }, ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => { - self.state = InitializeVisitorState::DontWarn + self.state = InitializeVisitorState::DontWarn; }, _ => (), } @@ -292,7 +292,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { return; } } - walk_pat(self, pat) + walk_pat(self, pat); } fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 914b583186c..66479ae264e 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -212,9 +212,9 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { let mut suggestions = vec![]; for ((root, span), path) in used { if path.len() == 1 { - suggestions.push((span, format!("{}::{}", root, path[0]))) + suggestions.push((span, format!("{}::{}", root, path[0]))); } else { - suggestions.push((span, format!("{}::{{{}}}", root, path.join(", ")))) + suggestions.push((span, format!("{}::{{{}}}", root, path.join(", ")))); } } @@ -231,7 +231,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { "remove the attribute and import the macro directly, try", help, Applicability::MaybeIncorrect, - ) + ); } } } diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 23428524dee..6a06090f6e2 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -123,7 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { kind_word, snippet(cx, pattern.span, "..")))] .into_iter().chain(strippings.into_iter().map(|span| (span, "".into()))), - ) + ); }); } } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 99c35ae3bbf..e1f80ab025c 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -125,7 +125,7 @@ fn lint_needless_cloning(cx: &LateContext<'_>, root: Span, receiver: Span) { "remove the `map` call", String::new(), Applicability::MachineApplicable, - ) + ); } fn lint(cx: &LateContext<'_>, replace: Span, root: Span, copied: bool) { @@ -142,7 +142,7 @@ fn lint(cx: &LateContext<'_>, replace: Span, root: Span, copied: bool) { snippet_with_applicability(cx, root, "..", &mut applicability) ), applicability, - ) + ); } else { span_lint_and_sugg( cx, @@ -155,6 +155,6 @@ fn lint(cx: &LateContext<'_>, replace: Span, root: Span, copied: bool) { snippet_with_applicability(cx, root, "..", &mut applicability) ), applicability, - ) + ); } } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index fcd37687010..e07d8ea56e4 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1144,7 +1144,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) "try this", suggestions.join(" | "), Applicability::MaybeIncorrect, - ) + ); }, }; } @@ -1242,7 +1242,7 @@ fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp cast, ), applicability, - ) + ); } } } @@ -1494,7 +1494,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A "consider using the scrutinee and body instead", sugg, applicability, - ) + ); } else { span_lint_and_sugg( cx, @@ -1747,7 +1747,7 @@ mod redundant_pattern_match { match match_source { MatchSource::Normal => find_sugg_for_match(cx, expr, op, arms), MatchSource::IfLetDesugar { contains_else_clause } => { - find_sugg_for_if_let(cx, expr, op, &arms[0], "if", *contains_else_clause) + find_sugg_for_if_let(cx, expr, op, &arms[0], "if", *contains_else_clause); }, MatchSource::WhileLetDesugar => find_sugg_for_if_let(cx, expr, op, &arms[0], "while", false), _ => {}, @@ -1876,7 +1876,7 @@ mod redundant_pattern_match { { self.res = true; } else { - self.visit_expr(self_arg) + self.visit_expr(self_arg); } } args.iter().for_each(|arg| self.visit_expr(arg)); diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 287bff886bf..da428a7b487 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -135,7 +135,7 @@ pub(crate) trait BindInsteadOfMap { .into_iter() .map(|(span1, span2)| (span1, snippet(cx, span2, "_").into())), ), - ) + ); }); true } diff --git a/clippy_lints/src/methods/cloned_instead_of_copied.rs b/clippy_lints/src/methods/cloned_instead_of_copied.rs index ecec6da3aa0..f5b4b6bf8ea 100644 --- a/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -41,5 +41,5 @@ pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, "try", "copied".into(), Applicability::MachineApplicable, - ) + ); } diff --git a/clippy_lints/src/methods/flat_map_option.rs b/clippy_lints/src/methods/flat_map_option.rs index 12d560653ed..32d40d97bf4 100644 --- a/clippy_lints/src/methods/flat_map_option.rs +++ b/clippy_lints/src/methods/flat_map_option.rs @@ -30,5 +30,5 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, arg "try", "filter_map".into(), Applicability::MachineApplicable, - ) + ); } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e0d29682146..cabfe8023ef 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1951,7 +1951,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio if let Some((name, [recv, args @ ..], span)) = method_call!(expr) { match (name, args) { ("add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub", [recv, _]) => { - zst_offset::check(cx, expr, recv) + zst_offset::check(cx, expr, recv); }, ("and_then", [arg]) => { let biom_option_linted = bind_instead_of_map::OptionAndThenSome::check(cx, expr, recv, arg); @@ -2012,7 +2012,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio ("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, msrv), ("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, msrv), ("filter", [f_arg]) => { - filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, false) + filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, false); }, ("find", [f_arg]) => filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, true), _ => {}, @@ -2058,7 +2058,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]); }, Some(("map", [m_recv, m_arg], span)) => { - option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span) + option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span); }, _ => {}, }, @@ -2073,7 +2073,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio fn check_is_some_is_none(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, is_some: bool) { if let Some((name @ ("find" | "position" | "rposition"), [f_recv, arg], span)) = method_call!(recv) { - search_is_some::check(cx, expr, name, is_some, f_recv, arg, recv, span) + search_is_some::check(cx, expr, name, is_some, f_recv, arg, recv, span); } } diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 75517c48a21..4c4034437da 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -87,7 +87,7 @@ pub(super) fn check( ast::LitKind::Bool(true) => check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::And, "all", true), ast::LitKind::Int(0, _) => check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Add, "sum", false), ast::LitKind::Int(1, _) => { - check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Mul, "product", false) + check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Mul, "product", false); }, _ => (), } diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index dd38316fa25..050b6805b7c 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -310,7 +310,7 @@ impl EarlyLintPass for MiscEarlyLints { if in_external_macro(cx.sess(), expr.span) { return; } - double_neg::check(cx, expr) + double_neg::check(cx, expr); } } @@ -334,15 +334,15 @@ impl MiscEarlyLints { }; unseparated_literal_suffix::check(cx, lit, &lit_snip, suffix, "integer"); if lit_snip.starts_with("0x") { - mixed_case_hex_literals::check(cx, lit, suffix, &lit_snip) + mixed_case_hex_literals::check(cx, lit, suffix, &lit_snip); } else if lit_snip.starts_with("0b") || lit_snip.starts_with("0o") { - /* nothing to do */ + // nothing to do } else if value != 0 && lit_snip.starts_with('0') { - zero_prefixed_literal::check(cx, lit, &lit_snip) + zero_prefixed_literal::check(cx, lit, &lit_snip); } } else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind { let suffix = float_ty.name_str(); - unseparated_literal_suffix::check(cx, lit, &lit_snip, suffix, "float") + unseparated_literal_suffix::check(cx, lit, &lit_snip, suffix, "float"); } } } diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index cea6fce1195..6efe8ffcde0 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); - check_arguments(cx, arguments, method_type, &path.ident.as_str(), "method") + check_arguments(cx, arguments, method_type, &path.ident.as_str(), "method"); }, _ => (), } diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 533c5a22db0..81bf853300f 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -103,7 +103,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { _ if !self.found => self.expr_span = Some(expr.span), _ => return, } - walk_expr(self, expr) + walk_expr(self, expr); } fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index 3e2b2782ed5..fe3c4455be5 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -121,7 +121,7 @@ impl EarlyLintPass for NeedlessArbitrarySelfType { match &p.ty.kind { TyKind::Path(None, path) => { if let PatKind::Ident(BindingMode::ByValue(mutbl), _, _) = p.pat.kind { - check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl) + check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl); } }, TyKind::Rptr(lifetime, mut_ty) => { @@ -129,7 +129,7 @@ impl EarlyLintPass for NeedlessArbitrarySelfType { if let TyKind::Path(None, path) = &mut_ty.ty.kind; if let PatKind::Ident(BindingMode::ByValue(Mutability::Not), _, _) = p.pat.kind; then { - check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl) + check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl); } } }, diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index dd458198637..3b3736fd3a1 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool { } if is_else_clause(cx.tcx, e) { - snip = snip.blockify() + snip = snip.blockify(); } span_lint_and_sugg( @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for BoolComparison { |h: Sugg<'_>| !h, "equality checks against false can be replaced by a negation", )); - check_comparison(cx, e, true_case, false_case, true_case, false_case, ignore_no_literal) + check_comparison(cx, e, true_case, false_case, true_case, false_case, ignore_no_literal); }, BinOpKind::Ne => { let true_case = Some(( @@ -152,7 +152,7 @@ impl<'tcx> LateLintPass<'tcx> for BoolComparison { "inequality checks against true can be replaced by a negation", )); let false_case = Some((|h| h, "inequality checks against false are unnecessary")); - check_comparison(cx, e, true_case, false_case, true_case, false_case, ignore_no_literal) + check_comparison(cx, e, true_case, false_case, true_case, false_case, ignore_no_literal); }, BinOpKind::Lt => check_comparison( cx, @@ -251,22 +251,22 @@ fn check_comparison<'a, 'tcx>( snippet_with_applicability(cx, expression_info.right_span, "..", &mut applicability) ), applicability, - ) + ); } } match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) { (Bool(true), Other) => left_true.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, right_side, applicability, m, h) + suggest_bool_comparison(cx, e, right_side, applicability, m, h); }), (Other, Bool(true)) => right_true.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, left_side, applicability, m, h) + suggest_bool_comparison(cx, e, left_side, applicability, m, h); }), (Bool(false), Other) => left_false.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, right_side, applicability, m, h) + suggest_bool_comparison(cx, e, right_side, applicability, m, h); }), (Other, Bool(false)) => right_false.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, left_side, applicability, m, h) + suggest_bool_comparison(cx, e, left_side, applicability, m, h); }), (Other, Other) => no_literal.map_or((), |(h, m)| { let left_side = Sugg::hir_with_applicability(cx, left_side, "..", &mut applicability); @@ -279,7 +279,7 @@ fn check_comparison<'a, 'tcx>( "try simplifying it as shown", h(left_side, right_side).to_string(), applicability, - ) + ); }), _ => (), } diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index bcedebfccc7..dd1dfa2bdfb 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { |diag| { diag.multipart_suggestion("try this", replacements, app); }, - ) + ); } self.current_body = None; } diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 079b6642d58..3b936e6aaef 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -145,7 +145,7 @@ impl<'tcx> Visitor<'tcx> for RetCollector { self.ret_in_loop = true } - self.spans.push(expr.span) + self.spans.push(expr.span); }, ExprKind::Loop(..) => { diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index e70f8a09ebe..39ef170ae36 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -292,7 +292,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { LitKind::Str(ref text, _) => { let str_pat = self.next("s"); println!(" if let LitKind::Str(ref {}, _) = {}.node;", str_pat, lit_pat); - println!(" if {}.as_str() == {:?}", str_pat, &*text.as_str()) + println!(" if {}.as_str() == {:?}", str_pat, &*text.as_str()); }, } }, diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index ee7be24eae8..2c73c3d929b 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1100,7 +1100,7 @@ impl<'tcx> LateLintPass<'tcx> for IfChainStyle { IF_CHAIN_STYLE, if_chain_local_span(cx, local, if_chain_span), "`let` expression should be inside `then { .. }`", - ) + ); } } @@ -1141,7 +1141,7 @@ impl<'tcx> LateLintPass<'tcx> for IfChainStyle { if is_first_if_chain_expr(cx, expr.hir_id, if_chain_span) && is_if_chain_then(then_block.stmts, then_block.expr, if_chain_span) { - span_lint(cx, IF_CHAIN_STYLE, expr.span, "`if_chain!` only has one `if`") + span_lint(cx, IF_CHAIN_STYLE, expr.span, "`if_chain!` only has one `if`"); } } } diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index a672af88271..46af03663b8 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -818,7 +818,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for IsMultiSpanScanner<'a, 'hir> { .any(|func_path| match_function_call(self.cx, fn_expr, func_path).is_some()); if found_function { // These functions are all multi part suggestions - self.add_single_span_suggestion() + self.add_single_span_suggestion(); } }, ExprKind::MethodCall(path, _path_span, arg, _arg_span) => { -- cgit 1.4.1-3-g733a5 From 12c61612f7a91df64121dd9c991828c26d665325 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Fri, 2 Jul 2021 20:37:11 +0200 Subject: Update lint documentation to use markdown headlines --- clippy_dev/src/new_lint.rs | 9 +- clippy_lints/src/absurd_extreme_comparisons.rs | 12 +- clippy_lints/src/approx_const.rs | 10 +- clippy_lints/src/arithmetic.rs | 20 +- clippy_lints/src/as_conversions.rs | 10 +- clippy_lints/src/asm_syntax.rs | 20 +- clippy_lints/src/assertions_on_constants.rs | 11 +- clippy_lints/src/assign_ops.rs | 22 +- clippy_lints/src/async_yields_async.rs | 11 +- clippy_lints/src/atomic_ordering.rs | 10 +- clippy_lints/src/attrs.rs | 74 +-- clippy_lints/src/await_holding_invalid.rs | 24 +- clippy_lints/src/bit_mask.rs | 32 +- clippy_lints/src/blacklisted_name.rs | 10 +- clippy_lints/src/blocks_in_if_conditions.rs | 10 +- clippy_lints/src/bool_assert_comparison.rs | 11 +- clippy_lints/src/booleans.rs | 22 +- clippy_lints/src/bytecount.rs | 12 +- clippy_lints/src/cargo_common_metadata.rs | 10 +- .../case_sensitive_file_extension_comparisons.rs | 9 +- clippy_lints/src/casts/mod.rs | 116 ++-- clippy_lints/src/checked_conversions.rs | 10 +- clippy_lints/src/cognitive_complexity.rs | 12 +- clippy_lints/src/collapsible_if.rs | 20 +- clippy_lints/src/collapsible_match.rs | 11 +- clippy_lints/src/comparison_chain.rs | 11 +- clippy_lints/src/copies.rs | 40 +- clippy_lints/src/copy_iterator.rs | 10 +- clippy_lints/src/create_dir.rs | 10 +- clippy_lints/src/dbg_macro.rs | 10 +- clippy_lints/src/default.rs | 21 +- clippy_lints/src/default_numeric_fallback.rs | 11 +- clippy_lints/src/deprecated_lints.rs | 96 ++-- clippy_lints/src/dereference.rs | 8 +- clippy_lints/src/derive.rs | 43 +- clippy_lints/src/disallowed_method.rs | 11 +- clippy_lints/src/disallowed_script_idents.rs | 10 +- clippy_lints/src/disallowed_type.rs | 11 +- clippy_lints/src/doc.rs | 53 +- clippy_lints/src/double_comparison.rs | 10 +- clippy_lints/src/double_parens.rs | 10 +- clippy_lints/src/drop_forget_ref.rs | 40 +- clippy_lints/src/duration_subsec.rs | 10 +- clippy_lints/src/else_if_without_else.rs | 10 +- clippy_lints/src/empty_enum.rs | 11 +- clippy_lints/src/entry.rs | 11 +- clippy_lints/src/enum_clike.rs | 10 +- clippy_lints/src/enum_variants.rs | 30 +- clippy_lints/src/eq_op.rs | 22 +- clippy_lints/src/erasing_op.rs | 10 +- clippy_lints/src/escape.rs | 10 +- clippy_lints/src/eta_reduction.rs | 22 +- clippy_lints/src/eval_order_dependence.rs | 22 +- clippy_lints/src/excessive_bools.rs | 20 +- clippy_lints/src/exhaustive_items.rs | 22 +- clippy_lints/src/exit.rs | 10 +- clippy_lints/src/explicit_write.rs | 10 +- clippy_lints/src/fallible_impl_from.rs | 10 +- clippy_lints/src/float_equality_without_abs.rs | 50 +- clippy_lints/src/float_literal.rs | 22 +- clippy_lints/src/floating_point_arithmetic.rs | 22 +- clippy_lints/src/format.rs | 10 +- clippy_lints/src/formatting.rs | 40 +- clippy_lints/src/from_over_into.rs | 11 +- clippy_lints/src/from_str_radix_10.rs | 12 +- clippy_lints/src/functions/mod.rs | 73 +-- clippy_lints/src/future_not_send.rs | 11 +- clippy_lints/src/get_last_with_len.rs | 11 +- clippy_lints/src/identity_op.rs | 10 +- clippy_lints/src/if_let_mutex.rs | 11 +- clippy_lints/src/if_let_some_result.rs | 10 +- clippy_lints/src/if_not_else.rs | 10 +- clippy_lints/src/if_then_some_else_none.rs | 11 +- clippy_lints/src/implicit_hasher.rs | 11 +- clippy_lints/src/implicit_return.rs | 10 +- clippy_lints/src/implicit_saturating_sub.rs | 11 +- .../src/inconsistent_struct_constructor.rs | 11 +- clippy_lints/src/indexing_slicing.rs | 22 +- clippy_lints/src/infinite_iter.rs | 21 +- clippy_lints/src/inherent_impl.rs | 10 +- clippy_lints/src/inherent_to_string.rs | 24 +- clippy_lints/src/inline_fn_without_body.rs | 10 +- clippy_lints/src/int_plus_one.rs | 10 +- clippy_lints/src/integer_division.rs | 10 +- clippy_lints/src/invalid_upcast_comparisons.rs | 10 +- clippy_lints/src/items_after_statements.rs | 10 +- clippy_lints/src/large_const_arrays.rs | 10 +- clippy_lints/src/large_enum_variant.rs | 12 +- clippy_lints/src/large_stack_arrays.rs | 10 +- clippy_lints/src/len_zero.rs | 30 +- clippy_lints/src/let_if_seq.rs | 10 +- clippy_lints/src/let_underscore.rs | 30 +- clippy_lints/src/lib.rs | 11 +- clippy_lints/src/lifetimes.rs | 20 +- clippy_lints/src/literal_representation.rs | 66 +-- clippy_lints/src/loops/mod.rs | 182 +++--- clippy_lints/src/macro_use.rs | 10 +- clippy_lints/src/main_recursion.rs | 10 +- clippy_lints/src/manual_async_fn.rs | 11 +- clippy_lints/src/manual_map.rs | 11 +- clippy_lints/src/manual_non_exhaustive.rs | 11 +- clippy_lints/src/manual_ok_or.rs | 10 +- clippy_lints/src/manual_strip.rs | 10 +- clippy_lints/src/manual_unwrap_or.rs | 8 +- clippy_lints/src/map_clone.rs | 11 +- clippy_lints/src/map_err_ignore.rs | 10 +- clippy_lints/src/map_unit_fn.rs | 22 +- clippy_lints/src/match_on_vec_items.rs | 10 +- clippy_lints/src/matches.rs | 170 +++--- clippy_lints/src/mem_discriminant.rs | 10 +- clippy_lints/src/mem_forget.rs | 10 +- clippy_lints/src/mem_replace.rs | 31 +- clippy_lints/src/methods/mod.rs | 636 +++++++++++---------- clippy_lints/src/minmax.rs | 10 +- clippy_lints/src/misc.rs | 93 +-- clippy_lints/src/misc_early/mod.rs | 90 +-- clippy_lints/src/missing_const_for_fn.rs | 12 +- clippy_lints/src/missing_doc.rs | 8 +- clippy_lints/src/missing_enforced_import_rename.rs | 11 +- clippy_lints/src/missing_inline.rs | 10 +- clippy_lints/src/modulo_arithmetic.rs | 10 +- clippy_lints/src/multiple_crate_versions.rs | 11 +- clippy_lints/src/mut_key.rs | 11 +- clippy_lints/src/mut_mut.rs | 10 +- clippy_lints/src/mut_mutex_lock.rs | 11 +- clippy_lints/src/mut_reference.rs | 10 +- clippy_lints/src/mutable_debug_assertion.rs | 10 +- clippy_lints/src/mutex_atomic.rs | 22 +- clippy_lints/src/needless_arbitrary_self_type.rs | 10 +- clippy_lints/src/needless_bitwise_bool.rs | 9 +- clippy_lints/src/needless_bool.rs | 21 +- clippy_lints/src/needless_borrow.rs | 20 +- clippy_lints/src/needless_borrowed_ref.rs | 11 +- clippy_lints/src/needless_continue.rs | 10 +- clippy_lints/src/needless_for_each.rs | 11 +- clippy_lints/src/needless_pass_by_value.rs | 10 +- clippy_lints/src/needless_question_mark.rs | 10 +- clippy_lints/src/needless_update.rs | 10 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 9 +- clippy_lints/src/neg_multiply.rs | 11 +- clippy_lints/src/new_without_default.rs | 11 +- clippy_lints/src/no_effect.rs | 20 +- clippy_lints/src/non_copy_const.rs | 22 +- clippy_lints/src/non_expressive_names.rs | 30 +- clippy_lints/src/non_octal_unix_permissions.rs | 11 +- clippy_lints/src/nonstandard_macro_braces.rs | 12 +- clippy_lints/src/open_options.rs | 10 +- clippy_lints/src/option_env_unwrap.rs | 11 +- clippy_lints/src/option_if_let_else.rs | 9 +- clippy_lints/src/overflow_check_conditional.rs | 10 +- clippy_lints/src/panic_in_result_fn.rs | 12 +- clippy_lints/src/panic_unimplemented.rs | 40 +- clippy_lints/src/partialeq_ne_impl.rs | 10 +- clippy_lints/src/pass_by_ref_or_value.rs | 20 +- clippy_lints/src/path_buf_push_overwrite.rs | 10 +- clippy_lints/src/pattern_type_mismatch.rs | 11 +- clippy_lints/src/precedence.rs | 10 +- clippy_lints/src/ptr.rs | 42 +- clippy_lints/src/ptr_eq.rs | 11 +- clippy_lints/src/ptr_offset_with_cast.rs | 10 +- clippy_lints/src/question_mark.rs | 10 +- clippy_lints/src/ranges.rs | 54 +- clippy_lints/src/redundant_clone.rs | 11 +- clippy_lints/src/redundant_closure_call.rs | 10 +- clippy_lints/src/redundant_else.rs | 12 +- clippy_lints/src/redundant_field_names.rs | 10 +- clippy_lints/src/redundant_pub_crate.rs | 11 +- clippy_lints/src/redundant_slicing.rs | 12 +- clippy_lints/src/redundant_static_lifetimes.rs | 10 +- clippy_lints/src/ref_option_ref.rs | 12 +- clippy_lints/src/reference.rs | 19 +- clippy_lints/src/regex.rs | 21 +- clippy_lints/src/repeat_once.rs | 11 +- clippy_lints/src/returns.rs | 20 +- clippy_lints/src/self_assignment.rs | 12 +- clippy_lints/src/self_named_constructor.rs | 11 +- clippy_lints/src/semicolon_if_nothing_returned.rs | 11 +- clippy_lints/src/serde_api.rs | 11 +- clippy_lints/src/shadow.rs | 33 +- clippy_lints/src/single_component_path_imports.rs | 11 +- clippy_lints/src/size_of_in_element_count.rs | 10 +- clippy_lints/src/slow_vector_initialization.rs | 10 +- clippy_lints/src/stable_sort_primitive.rs | 10 +- clippy_lints/src/strings.rs | 63 +- clippy_lints/src/strlen_on_c_strings.rs | 11 +- clippy_lints/src/suspicious_operation_groupings.rs | 11 +- clippy_lints/src/suspicious_trait_impl.rs | 20 +- clippy_lints/src/swap.rs | 20 +- clippy_lints/src/tabs_in_doc_comments.rs | 10 +- clippy_lints/src/temporary_assignment.rs | 10 +- clippy_lints/src/to_digit_is_some.rs | 8 +- clippy_lints/src/to_string_in_display.rs | 10 +- clippy_lints/src/trait_bounds.rs | 20 +- clippy_lints/src/transmute/mod.rs | 122 ++-- clippy_lints/src/transmuting_null.rs | 11 +- clippy_lints/src/try_err.rs | 10 +- clippy_lints/src/types/mod.rs | 94 +-- clippy_lints/src/undropped_manually_drops.rs | 12 +- clippy_lints/src/unicode.rs | 32 +- clippy_lints/src/unit_return_expecting_ord.rs | 12 +- clippy_lints/src/unit_types/mod.rs | 30 +- clippy_lints/src/unnamed_address.rs | 22 +- clippy_lints/src/unnecessary_self_imports.rs | 12 +- clippy_lints/src/unnecessary_sort_by.rs | 9 +- clippy_lints/src/unnecessary_wraps.rs | 12 +- clippy_lints/src/unnested_or_patterns.rs | 11 +- clippy_lints/src/unsafe_removed_from_name.rs | 10 +- clippy_lints/src/unused_async.rs | 11 +- clippy_lints/src/unused_io_amount.rs | 11 +- clippy_lints/src/unused_self.rs | 10 +- clippy_lints/src/unused_unit.rs | 10 +- clippy_lints/src/unwrap.rs | 21 +- clippy_lints/src/unwrap_in_result.rs | 11 +- clippy_lints/src/upper_case_acronyms.rs | 12 +- clippy_lints/src/use_self.rs | 11 +- clippy_lints/src/useless_conversion.rs | 11 +- clippy_lints/src/utils/author.rs | 5 +- clippy_lints/src/utils/inspector.rs | 5 +- clippy_lints/src/utils/internal_lints.rs | 109 ++-- .../src/utils/internal_lints/metadata_collector.rs | 16 +- clippy_lints/src/vec.rs | 10 +- clippy_lints/src/vec_init_then_push.rs | 11 +- clippy_lints/src/vec_resize_to_zero.rs | 10 +- clippy_lints/src/verbose_file_reads.rs | 11 +- clippy_lints/src/wildcard_dependencies.rs | 11 +- clippy_lints/src/wildcard_imports.rs | 26 +- clippy_lints/src/write.rs | 92 +-- clippy_lints/src/zero_div_zero.rs | 10 +- clippy_lints/src/zero_sized_map_values.rs | 11 +- doc/adding_lints.md | 20 +- 230 files changed, 2717 insertions(+), 2474 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index 4676c2affad..3a81aaba6de 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -169,14 +169,11 @@ use rustc_session::{{declare_lint_pass, declare_tool_lint}}; {pass_import} declare_clippy_lint! {{ - /// **What it does:** + /// ### What it does /// - /// **Why is this bad?** - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? /// + /// ### Example /// ```rust /// // example code where clippy issues a warning /// ``` diff --git a/clippy_lints/src/absurd_extreme_comparisons.rs b/clippy_lints/src/absurd_extreme_comparisons.rs index 49d4350123f..1483f3f9185 100644 --- a/clippy_lints/src/absurd_extreme_comparisons.rs +++ b/clippy_lints/src/absurd_extreme_comparisons.rs @@ -11,24 +11,26 @@ use clippy_utils::ty::is_isize_or_usize; use clippy_utils::{clip, int_bits, unsext}; declare_clippy_lint! { - /// **What it does:** Checks for comparisons where one side of the relation is + /// ### What it does + /// Checks for comparisons where one side of the relation is /// either the minimum or maximum value for its type and warns if it involves a /// case that is always true or always false. Only integer and boolean types are /// checked. /// - /// **Why is this bad?** An expression like `min <= x` may misleadingly imply + /// ### Why is this bad? + /// An expression like `min <= x` may misleadingly imply /// that it is possible for `x` to be less than the minimum. Expressions like /// `max < x` are probably mistakes. /// - /// **Known problems:** For `usize` the size of the current compile target will + /// ### Known problems + /// For `usize` the size of the current compile target will /// be assumed (e.g., 64 bits on 64 bit systems). This means code that uses such /// a comparison to detect target pointer width will trigger this lint. One can /// use `mem::sizeof` and compare its value or conditional compilation /// attributes /// like `#[cfg(target_pointer_width = "64")] ..` instead. /// - /// **Example:** - /// + /// ### Example /// ```rust /// let vec: Vec = Vec::new(); /// if vec.len() <= 0 {} diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 3d04abe094d..6100f4e435a 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -7,21 +7,21 @@ use rustc_span::symbol; use std::f64::consts as f64; declare_clippy_lint! { - /// **What it does:** Checks for floating point literals that approximate + /// ### What it does + /// Checks for floating point literals that approximate /// constants which are defined in /// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants) /// or /// [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants), /// respectively, suggesting to use the predefined constant. /// - /// **Why is this bad?** Usually, the definition in the standard library is more + /// ### Why is this bad? + /// Usually, the definition in the standard library is more /// precise than what people come up with. If you find that your definition is /// actually more precise, please [file a Rust /// issue](https://github.com/rust-lang/rust/issues). /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = 3.14; /// let y = 1_f64 / x; diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 24c2a972811..36fe7b7a867 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -6,7 +6,8 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for integer arithmetic operations which could overflow or panic. + /// ### What it does + /// Checks for integer arithmetic operations which could overflow or panic. /// /// Specifically, checks for any operators (`+`, `-`, `*`, `<<`, etc) which are capable /// of overflowing according to the [Rust @@ -14,13 +15,12 @@ declare_clippy_lint! { /// or which can panic (`/`, `%`). No bounds analysis or sophisticated reasoning is /// attempted. /// - /// **Why is this bad?** Integer overflow will trigger a panic in debug builds or will wrap in + /// ### Why is this bad? + /// Integer overflow will trigger a panic in debug builds or will wrap in /// release mode. Division by zero will cause a panic in either mode. In some applications one /// wants explicitly checked, wrapping or saturating arithmetic. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let a = 0; /// a + 1; @@ -31,14 +31,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for float arithmetic. + /// ### What it does + /// Checks for float arithmetic. /// - /// **Why is this bad?** For some embedded systems or kernel development, it + /// ### Why is this bad? + /// For some embedded systems or kernel development, it /// can be useful to rule out floating-point numbers. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let a = 0.0; /// a + 1.0; diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index 4b31e16094e..7c39a3e2ce3 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -5,7 +5,8 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for usage of `as` conversions. + /// ### What it does + /// Checks for usage of `as` conversions. /// /// Note that this lint is specialized in linting *every single* use of `as` /// regardless of whether good alternatives exist or not. @@ -15,14 +16,13 @@ declare_clippy_lint! { /// There is a good explanation the reason why this lint should work in this way and how it is useful /// [in this issue](https://github.com/rust-lang/rust-clippy/issues/5122). /// - /// **Why is this bad?** `as` conversions will perform many kinds of + /// ### Why is this bad? + /// `as` conversions will perform many kinds of /// conversions, including silently lossy conversions and dangerous coercions. /// There are cases when it makes sense to use `as`, so the lint is /// Allow by default. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// let a: u32; /// ... diff --git a/clippy_lints/src/asm_syntax.rs b/clippy_lints/src/asm_syntax.rs index b970c71b753..825832eb79d 100644 --- a/clippy_lints/src/asm_syntax.rs +++ b/clippy_lints/src/asm_syntax.rs @@ -53,14 +53,14 @@ fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr } declare_clippy_lint! { - /// **What it does:** Checks for usage of Intel x86 assembly syntax. + /// ### What it does + /// Checks for usage of Intel x86 assembly syntax. /// - /// **Why is this bad?** The lint has been enabled to indicate a preference + /// ### Why is this bad? + /// The lint has been enabled to indicate a preference /// for AT&T x86 assembly syntax. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// ```rust,no_run /// # #![feature(asm)] @@ -89,14 +89,14 @@ impl EarlyLintPass for InlineAsmX86IntelSyntax { } declare_clippy_lint! { - /// **What it does:** Checks for usage of AT&T x86 assembly syntax. + /// ### What it does + /// Checks for usage of AT&T x86 assembly syntax. /// - /// **Why is this bad?** The lint has been enabled to indicate a preference + /// ### Why is this bad? + /// The lint has been enabled to indicate a preference /// for Intel x86 assembly syntax. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// ```rust,no_run /// # #![feature(asm)] diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 5235b2642d1..cb9347a923d 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -8,14 +8,17 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls. + /// ### What it does + /// Checks for `assert!(true)` and `assert!(false)` calls. /// - /// **Why is this bad?** Will be optimized out by the compiler or should probably be replaced by a + /// ### Why is this bad? + /// Will be optimized out by the compiler or should probably be replaced by a /// `panic!()` or `unreachable!()` /// - /// **Known problems:** None + /// ### Known problems + /// None /// - /// **Example:** + /// ### Example /// ```rust,ignore /// assert!(false) /// assert!(true) diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 17ce3cd809f..2097a1feff9 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -12,15 +12,18 @@ use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `a = a op b` or `a = b commutative_op a` + /// ### What it does + /// Checks for `a = a op b` or `a = b commutative_op a` /// patterns. /// - /// **Why is this bad?** These can be written as the shorter `a op= b`. + /// ### Why is this bad? + /// These can be written as the shorter `a op= b`. /// - /// **Known problems:** While forbidden by the spec, `OpAssign` traits may have + /// ### Known problems + /// While forbidden by the spec, `OpAssign` traits may have /// implementations that differ from the regular `Op` impl. /// - /// **Example:** + /// ### Example /// ```rust /// let mut a = 5; /// let b = 0; @@ -37,17 +40,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `a op= a op b` or `a op= b op a` patterns. + /// ### What it does + /// Checks for `a op= a op b` or `a op= b op a` patterns. /// - /// **Why is this bad?** Most likely these are bugs where one meant to write `a + /// ### Why is this bad? + /// Most likely these are bugs where one meant to write `a /// op= b`. /// - /// **Known problems:** Clippy cannot know for sure if `a op= a op b` should have + /// ### Known problems + /// Clippy cannot know for sure if `a op= a op b` should have /// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore, it suggests both. /// If `a op= a op b` is really the correct behaviour it should be /// written as `a = a op a op b` as it's less confusing. /// - /// **Example:** + /// ### Example /// ```rust /// let mut a = 5; /// let b = 2; diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index e6c7c68f91a..182736a5a20 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -7,15 +7,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for async blocks that yield values of types + /// ### What it does + /// Checks for async blocks that yield values of types /// that can themselves be awaited. /// - /// **Why is this bad?** An await is likely missing. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// An await is likely missing. /// + /// ### Example /// ```rust /// async fn foo() {} /// diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 7ceb01f5590..cece28e8b3c 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -8,16 +8,16 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for usage of invalid atomic + /// ### What it does + /// Checks for usage of invalid atomic /// ordering in atomic loads/stores/exchanges/updates and /// memory fences. /// - /// **Why is this bad?** Using an invalid atomic ordering + /// ### Why is this bad? + /// Using an invalid atomic ordering /// will cause a panic at run-time. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,no_run /// # use std::sync::atomic::{self, AtomicU8, Ordering}; /// diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index f272ed010a1..c9ff468874b 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -41,10 +41,12 @@ static UNIX_SYSTEMS: &[&str] = &[ static NON_UNIX_SYSTEMS: &[&str] = &["hermit", "none", "wasi"]; declare_clippy_lint! { - /// **What it does:** Checks for items annotated with `#[inline(always)]`, + /// ### What it does + /// Checks for items annotated with `#[inline(always)]`, /// unless the annotated function is empty or simply panics. /// - /// **Why is this bad?** While there are valid uses of this annotation (and once + /// ### Why is this bad? + /// While there are valid uses of this annotation (and once /// you know when to use it, by all means `allow` this lint), it's a common /// newbie-mistake to pepper one's code with it. /// @@ -52,11 +54,12 @@ declare_clippy_lint! { /// measure if that additional function call really affects your runtime profile /// sufficiently to make up for the increase in compile time. /// - /// **Known problems:** False positives, big time. This lint is meant to be + /// ### Known problems + /// False positives, big time. This lint is meant to be /// deactivated by everyone doing serious performance work. This means having /// done the measurement. /// - /// **Example:** + /// ### Example /// ```ignore /// #[inline(always)] /// fn not_quite_hot_code(..) { ... } @@ -67,7 +70,8 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `extern crate` and `use` items annotated with + /// ### What it does + /// Checks for `extern crate` and `use` items annotated with /// lint attributes. /// /// This lint permits `#[allow(unused_imports)]`, `#[allow(deprecated)]`, @@ -75,12 +79,11 @@ declare_clippy_lint! { /// `#[allow(clippy::enum_glob_use)]` on `use` items and `#[allow(unused_imports)]` on /// `extern crate` items with a `#[macro_use]` attribute. /// - /// **Why is this bad?** Lint attributes have no effect on crate imports. Most + /// ### Why is this bad? + /// Lint attributes have no effect on crate imports. Most /// likely a `!` was forgotten. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// // Bad /// #[deny(dead_code)] @@ -101,15 +104,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `#[deprecated]` annotations with a `since` + /// ### What it does + /// Checks for `#[deprecated]` annotations with a `since` /// field that is not a valid semantic version. /// - /// **Why is this bad?** For checking the version of the deprecation, it must be + /// ### Why is this bad? + /// For checking the version of the deprecation, it must be /// a valid semver. Failing that, the contained information is useless. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// #[deprecated(since = "forever")] /// fn something_else() { /* ... */ } @@ -120,20 +123,22 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for empty lines after outer attributes + /// ### What it does + /// Checks for empty lines after outer attributes /// - /// **Why is this bad?** + /// ### Why is this bad? /// Most likely the attribute was meant to be an inner attribute using a '!'. /// If it was meant to be an outer attribute, then the following item /// should not be separated by empty lines. /// - /// **Known problems:** Can cause false positives. + /// ### Known problems + /// Can cause false positives. /// /// From the clippy side it's difficult to detect empty lines between an attributes and the /// following item because empty lines and comments are not part of the AST. The parsing /// currently works for basic cases but is not perfect. /// - /// **Example:** + /// ### Example /// ```rust /// // Good (as inner attribute) /// #![allow(dead_code)] @@ -155,14 +160,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category. + /// ### What it does + /// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category. /// - /// **Why is this bad?** Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust. + /// ### Why is this bad? + /// Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust. /// These lints should only be enabled on a lint-by-lint basis and with careful consideration. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust /// #![deny(clippy::restriction)] @@ -178,18 +183,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it + /// ### What it does + /// Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it /// with `#[rustfmt::skip]`. /// - /// **Why is this bad?** Since tool_attributes ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690)) + /// ### Why is this bad? + /// Since tool_attributes ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690)) /// are stable now, they should be used instead of the old `cfg_attr(rustfmt)` attributes. /// - /// **Known problems:** This lint doesn't detect crate level inner attributes, because they get + /// ### Known problems + /// This lint doesn't detect crate level inner attributes, because they get /// processed before the PreExpansionPass lints get executed. See /// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765) /// - /// **Example:** - /// + /// ### Example /// Bad: /// ```rust /// #[cfg_attr(rustfmt, rustfmt_skip)] @@ -207,15 +214,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for cfg attributes having operating systems used in target family position. + /// ### What it does + /// Checks for cfg attributes having operating systems used in target family position. /// - /// **Why is this bad?** The configuration option will not be recognised and the related item will not be included + /// ### Why is this bad? + /// The configuration option will not be recognised and the related item will not be included /// by the conditional compilation engine. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// Bad: /// ```rust /// #[cfg(linux)] diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 1739a57a240..0cc79c8b6e8 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -8,10 +8,12 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for calls to await while holding a + /// ### What it does + /// Checks for calls to await while holding a /// non-async-aware MutexGuard. /// - /// **Why is this bad?** The Mutex types found in std::sync and parking_lot + /// ### Why is this bad? + /// The Mutex types found in std::sync and parking_lot /// are not designed to operate in an async context across await points. /// /// There are two potential solutions. One is to use an asynx-aware Mutex @@ -19,10 +21,10 @@ declare_clippy_lint! { /// other solution is to ensure the mutex is unlocked before calling await, /// either by introducing a scope or an explicit call to Drop::drop. /// - /// **Known problems:** Will report false positive for explicitly dropped guards ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). - /// - /// **Example:** + /// ### Known problems + /// Will report false positive for explicitly dropped guards ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). /// + /// ### Example /// ```rust,ignore /// use std::sync::Mutex; /// @@ -51,17 +53,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to await while holding a + /// ### What it does + /// Checks for calls to await while holding a /// `RefCell` `Ref` or `RefMut`. /// - /// **Why is this bad?** `RefCell` refs only check for exclusive mutable access + /// ### Why is this bad? + /// `RefCell` refs only check for exclusive mutable access /// at runtime. Holding onto a `RefCell` ref across an `await` suspension point /// risks panics from a mutable ref shared while other refs are outstanding. /// - /// **Known problems:** Will report false positive for explicitly dropped refs ([#6353](https://github.com/rust-lang/rust-clippy/issues/6353)). - /// - /// **Example:** + /// ### Known problems + /// Will report false positive for explicitly dropped refs ([#6353](https://github.com/rust-lang/rust-clippy/issues/6353)). /// + /// ### Example /// ```rust,ignore /// use std::cell::RefCell; /// diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 991ed94572c..11346e7c96a 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -10,7 +10,8 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for incompatible bit masks in comparisons. + /// ### What it does + /// Checks for incompatible bit masks in comparisons. /// /// The formula for detecting if an expression of the type `_ m /// c` (where `` is one of {`&`, `|`} and `` is one of @@ -26,7 +27,8 @@ declare_clippy_lint! { /// |`<` or `>=`| `|` |`x | 1 < 1` |`false` |`m >= c` | /// |`<=` or `>` | `|` |`x | 1 > 0` |`true` |`m > c` | /// - /// **Why is this bad?** If the bits that the comparison cares about are always + /// ### Why is this bad? + /// If the bits that the comparison cares about are always /// set to zero or one by the bit mask, the comparison is constant `true` or /// `false` (depending on mask, compared value, and operators). /// @@ -34,9 +36,7 @@ declare_clippy_lint! { /// this intentionally is to win an underhanded Rust contest or create a /// test-case for this lint. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// if (x & 1 == 2) { } @@ -47,7 +47,8 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for bit masks in comparisons which can be removed + /// ### What it does + /// Checks for bit masks in comparisons which can be removed /// without changing the outcome. The basic structure can be seen in the /// following table: /// @@ -56,16 +57,18 @@ declare_clippy_lint! { /// |`>` / `<=`|`|` / `^`|`x | 2 > 3`|`x > 3`| /// |`<` / `>=`|`|` / `^`|`x ^ 1 < 4`|`x < 4`| /// - /// **Why is this bad?** Not equally evil as [`bad_bit_mask`](#bad_bit_mask), + /// ### Why is this bad? + /// Not equally evil as [`bad_bit_mask`](#bad_bit_mask), /// but still a bit misleading, because the bit mask is ineffective. /// - /// **Known problems:** False negatives: This lint will only match instances + /// ### Known problems + /// False negatives: This lint will only match instances /// where we have figured out the math (which is for a power-of-two compared /// value). This means things like `x | 1 >= 7` (which would be better written /// as `x >= 6`) will not be reported (but bit masks like this are fairly /// uncommon). /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// if (x | 1 > 3) { } @@ -76,15 +79,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for bit masks that can be replaced by a call + /// ### What it does + /// Checks for bit masks that can be replaced by a call /// to `trailing_zeros` /// - /// **Why is this bad?** `x.trailing_zeros() > 4` is much clearer than `x & 15 + /// ### Why is this bad? + /// `x.trailing_zeros() > 4` is much clearer than `x & 15 /// == 0` /// - /// **Known problems:** llvm generates better code for `x & 15 == 0` on x86 + /// ### Known problems + /// llvm generates better code for `x & 15 == 0` on x86 /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// if x & 0b1111 == 0 { } diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index 8eb94f3c28e..916c78c982a 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -5,15 +5,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for usage of blacklisted names for variables, such + /// ### What it does + /// Checks for usage of blacklisted names for variables, such /// as `foo`. /// - /// **Why is this bad?** These names are usually placeholder names and should be + /// ### Why is this bad? + /// These names are usually placeholder names and should be /// avoided. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let foo = 3.14; /// ``` diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index badcf8d2a43..9b2e4f8998e 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -13,14 +13,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for `if` conditions that use blocks containing an + /// ### What it does + /// Checks for `if` conditions that use blocks containing an /// expression, statements or conditions that use closures with blocks. /// - /// **Why is this bad?** Style, using blocks in the condition makes it hard to read. + /// ### Why is this bad? + /// Style, using blocks in the condition makes it hard to read. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ```rust /// // Bad /// if { true } { /* ... */ } diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index bee706ed402..8d3f68565b2 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -6,14 +6,13 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** This lint warns about boolean comparisons in assert-like macros. + /// ### What it does + /// This lint warns about boolean comparisons in assert-like macros. /// - /// **Why is this bad?** It is shorter to use the equivalent. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// It is shorter to use the equivalent. /// + /// ### Example /// ```rust /// // Bad /// assert_eq!("a".is_empty(), false); diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index e72399af232..4a83d35a568 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -14,16 +14,19 @@ use rustc_span::source_map::Span; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for boolean expressions that can be written more + /// ### What it does + /// Checks for boolean expressions that can be written more /// concisely. /// - /// **Why is this bad?** Readability of boolean expressions suffers from + /// ### Why is this bad? + /// Readability of boolean expressions suffers from /// unnecessary duplication. /// - /// **Known problems:** Ignores short circuiting behavior of `||` and + /// ### Known problems + /// Ignores short circuiting behavior of `||` and /// `&&`. Ignores `|`, `&` and `^`. /// - /// **Example:** + /// ### Example /// ```ignore /// if a && true // should be: if a /// if !(a == b) // should be: if a != b @@ -34,14 +37,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for boolean expressions that contain terminals that + /// ### What it does + /// Checks for boolean expressions that contain terminals that /// can be eliminated. /// - /// **Why is this bad?** This is most likely a logic bug. + /// ### Why is this bad? + /// This is most likely a logic bug. /// - /// **Known problems:** Ignores short circuiting behavior. + /// ### Known problems + /// Ignores short circuiting behavior. /// - /// **Example:** + /// ### Example /// ```ignore /// if a && b || a { ... } /// ``` diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 4f7ffdcdfb4..c444984bc13 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -12,18 +12,20 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for naive byte counts + /// ### What it does + /// Checks for naive byte counts /// - /// **Why is this bad?** The [`bytecount`](https://crates.io/crates/bytecount) + /// ### Why is this bad? + /// The [`bytecount`](https://crates.io/crates/bytecount) /// crate has methods to count your bytes faster, especially for large slices. /// - /// **Known problems:** If you have predominantly small slices, the + /// ### Known problems + /// If you have predominantly small slices, the /// `bytecount::count(..)` method may actually be slower. However, if you can /// ensure that less than 2³²-1 matches arise, the `naive_count_32(..)` can be /// faster in those cases. /// - /// **Example:** - /// + /// ### Example /// ```rust /// # let vec = vec![1_u8]; /// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index 21c7b2448ce..bd5426ba707 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -9,15 +9,15 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::DUMMY_SP; declare_clippy_lint! { - /// **What it does:** Checks to see if all common metadata is defined in + /// ### What it does + /// Checks to see if all common metadata is defined in /// `Cargo.toml`. See: https://rust-lang-nursery.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata /// - /// **Why is this bad?** It will be more difficult for users to discover the + /// ### Why is this bad? + /// It will be more difficult for users to discover the /// purpose of the crate, and key information related to it. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```toml /// # This `Cargo.toml` is missing a description field: /// [package] diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index c9ef379be56..86b32475ceb 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -8,17 +8,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{source_map::Spanned, symbol::sym, Span}; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Checks for calls to `ends_with` with possible file extensions /// and suggests to use a case-insensitive approach instead. /// - /// **Why is this bad?** + /// ### Why is this bad? /// `ends_with` is case-sensitive and may not detect files with a valid extension. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// fn is_rust_file(filename: &str) -> bool { /// filename.ends_with(".rs") diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index ae4fdd12c41..27e1bea7993 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -20,7 +20,8 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for casts from any numerical to a float type where + /// ### What it does + /// Checks for casts from any numerical to a float type where /// the receiving type cannot store all values from the original type without /// rounding errors. This possible rounding is to be expected, so this lint is /// `Allow` by default. @@ -28,13 +29,12 @@ declare_clippy_lint! { /// Basically, this warns on casting any integer with 32 or more bits to `f32` /// or any 64-bit integer to `f64`. /// - /// **Why is this bad?** It's not bad at all. But in some applications it can be + /// ### Why is this bad? + /// It's not bad at all. But in some applications it can be /// helpful to know where precision loss can take place. This lint can help find /// those places in the code. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = u64::MAX; /// x as f64; @@ -45,17 +45,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts from a signed to an unsigned numerical + /// ### What it does + /// Checks for casts from a signed to an unsigned numerical /// type. In this case, negative values wrap around to large positive values, /// which can be quite surprising in practice. However, as the cast works as /// defined, this lint is `Allow` by default. /// - /// **Why is this bad?** Possibly surprising results. You can activate this lint + /// ### Why is this bad? + /// Possibly surprising results. You can activate this lint /// as a one-time check to see where numerical wrapping can arise. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let y: i8 = -1; /// y as u128; // will return 18446744073709551615 @@ -66,17 +66,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts between numerical types that may + /// ### What it does + /// Checks for casts between numerical types that may /// truncate large values. This is expected behavior, so the cast is `Allow` by /// default. /// - /// **Why is this bad?** In some problem domains, it is good practice to avoid + /// ### Why is this bad? + /// In some problem domains, it is good practice to avoid /// truncation. This lint can be activated to help assess where additional /// checks could be beneficial. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn as_u8(x: u64) -> u8 { /// x as u8 @@ -88,20 +88,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts from an unsigned type to a signed type of + /// ### What it does + /// Checks for casts from an unsigned type to a signed type of /// the same size. Performing such a cast is a 'no-op' for the compiler, /// i.e., nothing is changed at the bit level, and the binary representation of /// the value is reinterpreted. This can cause wrapping if the value is too big /// for the target signed type. However, the cast works as defined, so this lint /// is `Allow` by default. /// - /// **Why is this bad?** While such a cast is not bad in itself, the results can + /// ### Why is this bad? + /// While such a cast is not bad in itself, the results can /// be surprising when this is not the intended behavior, as demonstrated by the /// example below. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// u32::MAX as i32; // will yield a value of `-1` /// ``` @@ -111,19 +111,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts between numerical types that may + /// ### What it does + /// Checks for casts between numerical types that may /// be replaced by safe conversion functions. /// - /// **Why is this bad?** Rust's `as` keyword will perform many kinds of + /// ### Why is this bad? + /// Rust's `as` keyword will perform many kinds of /// conversions, including silently lossy conversions. Conversion functions such /// as `i32::from` will only perform lossless conversions. Using the conversion /// functions prevents conversions from turning into silent lossy conversions if /// the types of the input expressions ever change, and make it easier for /// people reading the code to know that the conversion is lossless. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn as_u64(x: u8) -> u64 { /// x as u64 @@ -143,14 +143,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts to the same type, casts of int literals to integer types + /// ### What it does + /// Checks for casts to the same type, casts of int literals to integer types /// and casts of float literals to float types. /// - /// **Why is this bad?** It's just unnecessary. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// It's just unnecessary. /// - /// **Example:** + /// ### Example /// ```rust /// let _ = 2i32 as i32; /// let _ = 0.5 as f32; @@ -168,17 +168,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts, using `as` or `pointer::cast`, + /// ### What it does + /// Checks for casts, using `as` or `pointer::cast`, /// from a less-strictly-aligned pointer to a more-strictly-aligned pointer /// - /// **Why is this bad?** Dereferencing the resulting pointer may be undefined + /// ### Why is this bad? + /// Dereferencing the resulting pointer may be undefined /// behavior. /// - /// **Known problems:** Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar + /// ### Known problems + /// Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar /// on the resulting pointer is fine. Is over-zealous: Casts with manual alignment checks or casts like /// u64-> u8 -> u16 can be fine. Miri is able to do a more in-depth analysis. /// - /// **Example:** + /// ### Example /// ```rust /// let _ = (&1u8 as *const u8) as *const u16; /// let _ = (&mut 1u8 as *mut u8) as *mut u16; @@ -192,9 +195,10 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts of function pointers to something other than usize + /// ### What it does + /// Checks for casts of function pointers to something other than usize /// - /// **Why is this bad?** + /// ### Why is this bad? /// Casting a function pointer to anything other than usize/isize is not portable across /// architectures, because you end up losing bits if the target type is too small or end up with a /// bunch of extra bits that waste space and add more instructions to the final binary than @@ -202,8 +206,7 @@ declare_clippy_lint! { /// /// Casting to isize also doesn't make sense since there are no signed addresses. /// - /// **Example** - /// + /// ### Example /// ```rust /// // Bad /// fn fun() -> i32 { 1 } @@ -219,16 +222,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts of a function pointer to a numeric type not wide enough to + /// ### What it does + /// Checks for casts of a function pointer to a numeric type not wide enough to /// store address. /// - /// **Why is this bad?** + /// ### Why is this bad? /// Such a cast discards some bits of the function's address. If this is intended, it would be more /// clearly expressed by casting to usize first, then casting the usize to the intended type (with /// a comment) to perform the truncation. /// - /// **Example** - /// + /// ### Example /// ```rust /// // Bad /// fn fn1() -> i16 { @@ -249,15 +252,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for casts of `&T` to `&mut T` anywhere in the code. + /// ### What it does + /// Checks for casts of `&T` to `&mut T` anywhere in the code. /// - /// **Why is this bad?** It’s basically guaranteed to be undefined behaviour. + /// ### Why is this bad? + /// It’s basically guaranteed to be undefined behaviour. /// `UnsafeCell` is the only way to obtain aliasable data that is considered /// mutable. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// fn x(r: &i32) { /// unsafe { @@ -283,18 +286,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for expressions where a character literal is cast + /// ### What it does + /// Checks for expressions where a character literal is cast /// to `u8` and suggests using a byte literal instead. /// - /// **Why is this bad?** In general, casting values to smaller types is + /// ### Why is this bad? + /// In general, casting values to smaller types is /// error-prone and should be avoided where possible. In the particular case of /// converting a character literal to u8, it is easy to avoid by just using a /// byte literal instead. As an added bonus, `b'a'` is even slightly shorter /// than `'a' as u8`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// 'x' as u8 /// ``` @@ -310,18 +313,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Checks for `as` casts between raw pointers without changing its mutability, /// namely `*const T` to `*const U` and `*mut T` to `*mut U`. /// - /// **Why is this bad?** + /// ### Why is this bad? /// Though `as` casts between raw pointers is not terrible, `pointer::cast` is safer because /// it cannot accidentally change the pointer's mutability nor cast the pointer to other types like `usize`. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let ptr: *const u32 = &42_u32; /// let mut_ptr: *mut u32 = &mut 42_u32; diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 8d3123e1ec8..842bbf006cc 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -13,13 +13,13 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for explicit bounds checking when casting. + /// ### What it does + /// Checks for explicit bounds checking when casting. /// - /// **Why is this bad?** Reduces the readability of statements & is error prone. + /// ### Why is this bad? + /// Reduces the readability of statements & is error prone. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let foo: u32 = 5; /// # let _ = diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index f62c6a9c325..96c30d57ee1 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -14,15 +14,19 @@ use rustc_span::source_map::Span; use rustc_span::{sym, BytePos}; declare_clippy_lint! { - /// **What it does:** Checks for methods with high cognitive complexity. + /// ### What it does + /// Checks for methods with high cognitive complexity. /// - /// **Why is this bad?** Methods of high cognitive complexity tend to be hard to + /// ### Why is this bad? + /// Methods of high cognitive complexity tend to be hard to /// both read and maintain. Also LLVM will tend to optimize small methods better. /// - /// **Known problems:** Sometimes it's hard to find a way to reduce the + /// ### Known problems + /// Sometimes it's hard to find a way to reduce the /// complexity. /// - /// **Example:** No. You'll see it when you get the warning. + /// ### Example + /// No. You'll see it when you get the warning. pub COGNITIVE_COMPLEXITY, nursery, "functions that should be split up into multiple functions" diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index 6e950738239..4aa87980715 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -22,15 +22,15 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for nested `if` statements which can be collapsed + /// ### What it does + /// Checks for nested `if` statements which can be collapsed /// by `&&`-combining their conditions. /// - /// **Why is this bad?** Each `if`-statement adds one level of nesting, which + /// ### Why is this bad? + /// Each `if`-statement adds one level of nesting, which /// makes code look more complex than it really is. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// if x { /// if y { @@ -53,15 +53,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for collapsible `else { if ... }` expressions + /// ### What it does + /// Checks for collapsible `else { if ... }` expressions /// that can be collapsed to `else if ...`. /// - /// **Why is this bad?** Each `if`-statement adds one level of nesting, which + /// ### Why is this bad? + /// Each `if`-statement adds one level of nesting, which /// makes code look more complex than it really is. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// /// if x { diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index a6c3a5b0e83..a403a9846ba 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -9,18 +9,17 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{MultiSpan, Span}; declare_clippy_lint! { - /// **What it does:** Finds nested `match` or `if let` expressions where the patterns may be "collapsed" together + /// ### What it does + /// Finds nested `match` or `if let` expressions where the patterns may be "collapsed" together /// without adding any branches. /// /// Note that this lint is not intended to find _all_ cases where nested match patterns can be merged, but only /// cases where merging would most likely make the code more readable. /// - /// **Why is this bad?** It is unnecessarily verbose and complex. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// It is unnecessarily verbose and complex. /// + /// ### Example /// ```rust /// fn func(opt: Option>) { /// let n = match opt { diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index b6999bef6e7..597a3c67024 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -6,16 +6,19 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks comparison chains written with `if` that can be + /// ### What it does + /// Checks comparison chains written with `if` that can be /// rewritten with `match` and `cmp`. /// - /// **Why is this bad?** `if` is not guaranteed to be exhaustive and conditionals can get + /// ### Why is this bad? + /// `if` is not guaranteed to be exhaustive and conditionals can get /// repetitive /// - /// **Known problems:** The match statement may be slower due to the compiler + /// ### Known problems + /// The match statement may be slower due to the compiler /// not inlining the call to cmp. See issue [#5354](https://github.com/rust-lang/rust-clippy/issues/5354) /// - /// **Example:** + /// ### Example /// ```rust,ignore /// # fn a() {} /// # fn b() {} diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 9cbcde59768..2dcd5545799 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -16,13 +16,13 @@ use rustc_span::{source_map::Span, symbol::Symbol, BytePos}; use std::borrow::Cow; declare_clippy_lint! { - /// **What it does:** Checks for consecutive `if`s with the same condition. + /// ### What it does + /// Checks for consecutive `if`s with the same condition. /// - /// **Why is this bad?** This is probably a copy & paste error. + /// ### Why is this bad? + /// This is probably a copy & paste error. /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** + /// ### Example /// ```ignore /// if a == b { /// … @@ -47,15 +47,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for consecutive `if`s with the same function call. + /// ### What it does + /// Checks for consecutive `if`s with the same function call. /// - /// **Why is this bad?** This is probably a copy & paste error. + /// ### Why is this bad? + /// This is probably a copy & paste error. /// Despite the fact that function can have side effects and `if` works as /// intended, such an approach is implicit and can be considered a "code smell". /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** + /// ### Example /// ```ignore /// if foo() == bar { /// … @@ -94,14 +94,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `if/else` with the same body as the *then* part + /// ### What it does + /// Checks for `if/else` with the same body as the *then* part /// and the *else* part. /// - /// **Why is this bad?** This is probably a copy & paste error. - /// - /// **Known problems:** Hopefully none. + /// ### Why is this bad? + /// This is probably a copy & paste error. /// - /// **Example:** + /// ### Example /// ```ignore /// let foo = if … { /// 42 @@ -115,17 +115,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks if the `if` and `else` block contain shared code that can be + /// ### What it does + /// Checks if the `if` and `else` block contain shared code that can be /// moved out of the blocks. /// - /// **Why is this bad?** Duplicate code is less maintainable. + /// ### Why is this bad? + /// Duplicate code is less maintainable. /// - /// **Known problems:** + /// ### Known problems /// * The lint doesn't check if the moved expressions modify values that are beeing used in /// the if condition. The suggestion can in that case modify the behavior of the program. /// See [rust-clippy#7452](https://github.com/rust-lang/rust-clippy/issues/7452) /// - /// **Example:** + /// ### Example /// ```ignore /// let foo = if … { /// println!("Hello World"); diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 35079c6bedc..c2e9e8b3ab7 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -8,15 +8,15 @@ use rustc_span::sym; use if_chain::if_chain; declare_clippy_lint! { - /// **What it does:** Checks for types that implement `Copy` as well as + /// ### What it does + /// Checks for types that implement `Copy` as well as /// `Iterator`. /// - /// **Why is this bad?** Implicit copies can be confusing when working with + /// ### Why is this bad? + /// Implicit copies can be confusing when working with /// iterator combinators. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// #[derive(Copy, Clone)] /// struct Countdown(u8); diff --git a/clippy_lints/src/create_dir.rs b/clippy_lints/src/create_dir.rs index 7b5cce6462a..e4ee2772483 100644 --- a/clippy_lints/src/create_dir.rs +++ b/clippy_lints/src/create_dir.rs @@ -8,13 +8,13 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks usage of `std::fs::create_dir` and suggest using `std::fs::create_dir_all` instead. + /// ### What it does + /// Checks usage of `std::fs::create_dir` and suggest using `std::fs::create_dir_all` instead. /// - /// **Why is this bad?** Sometimes `std::fs::create_dir` is mistakenly chosen over `std::fs::create_dir_all`. + /// ### Why is this bad? + /// Sometimes `std::fs::create_dir` is mistakenly chosen over `std::fs::create_dir_all`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// ```rust /// std::fs::create_dir("foo"); diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs index 286cc7e223e..bab4a696f83 100644 --- a/clippy_lints/src/dbg_macro.rs +++ b/clippy_lints/src/dbg_macro.rs @@ -8,14 +8,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for usage of dbg!() macro. + /// ### What it does + /// Checks for usage of dbg!() macro. /// - /// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It + /// ### Why is this bad? + /// `dbg!` macro is intended as a debugging tool. It /// should not be in version control. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// dbg!(true) diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 947479db8f5..db8f2171348 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -13,14 +13,14 @@ use rustc_span::symbol::{Ident, Symbol}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for literal calls to `Default::default()`. + /// ### What it does + /// Checks for literal calls to `Default::default()`. /// - /// **Why is this bad?** It's more clear to the reader to use the name of the type whose default is + /// ### Why is this bad? + /// It's more clear to the reader to use the name of the type whose default is /// being gotten than the generic `Default`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let s: String = Default::default(); @@ -34,14 +34,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for immediate reassignment of fields initialized + /// ### What it does + /// Checks for immediate reassignment of fields initialized /// with Default::default(). /// - /// **Why is this bad?**It's more idiomatic to use the [functional update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax). + /// ### Why is this bad? + ///It's more idiomatic to use the [functional update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax). /// - /// **Known problems:** Assignments to patterns that are of tuple type are not linted. + /// ### Known problems + /// Assignments to patterns that are of tuple type are not linted. /// - /// **Example:** + /// ### Example /// Bad: /// ``` /// # #[derive(Default)] diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index e719a1b0abf..3f1b7ea6214 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -18,7 +18,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::iter; declare_clippy_lint! { - /// **What it does:** Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type + /// ### What it does + /// Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type /// inference. /// /// Default numeric fallback means that if numeric types have not yet been bound to concrete @@ -27,12 +28,14 @@ declare_clippy_lint! { /// /// See [RFC0212](https://github.com/rust-lang/rfcs/blob/master/text/0212-restore-int-fallback.md) for more information about the fallback. /// - /// **Why is this bad?** For those who are very careful about types, default numeric fallback + /// ### Why is this bad? + /// For those who are very careful about types, default numeric fallback /// can be a pitfall that cause unexpected runtime behavior. /// - /// **Known problems:** This lint can only be allowed at the function level or above. + /// ### Known problems + /// This lint can only be allowed at the function level or above. /// - /// **Example:** + /// ### Example /// ```rust /// let i = 10; /// let f = 1.23; diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index 2933fbc9341..c604516742c 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -12,27 +12,33 @@ macro_rules! declare_deprecated_lint { } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend + /// ### Deprecation reason + /// This used to check for `assert!(a == b)` and recommend /// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011. pub SHOULD_ASSERT_EQ, "`assert!()` will be more flexible with RFC 2011" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than + /// ### Deprecation reason + /// This used to check for `Vec::extend`, which was slower than /// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true. pub EXTEND_FROM_SLICE, "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** `Range::step_by(0)` used to be linted since it's + /// ### Deprecation reason + /// `Range::step_by(0)` used to be linted since it's /// an infinite iterator, which is better expressed by `iter::repeat`, /// but the method has been removed for `Iterator::step_by` which panics /// if given a zero @@ -41,27 +47,33 @@ declare_deprecated_lint! { } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good + /// ### Deprecation reason + /// This used to check for `Vec::as_slice`, which was unstable with good /// stable alternatives. `Vec::as_slice` has now been stabilized. pub UNSTABLE_AS_SLICE, "`Vec::as_slice` has been stabilized in 1.7" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This used to check for `Vec::as_mut_slice`, which was unstable with good + /// ### Deprecation reason + /// This used to check for `Vec::as_mut_slice`, which was unstable with good /// stable alternatives. `Vec::as_mut_slice` has now been stabilized. pub UNSTABLE_AS_MUT_SLICE, "`Vec::as_mut_slice` has been stabilized in 1.7" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This lint should never have applied to non-pointer types, as transmuting + /// ### Deprecation reason + /// This lint should never have applied to non-pointer types, as transmuting /// between non-pointer types of differing alignment is well-defined behavior (it's semantically /// equivalent to a memcpy). This lint has thus been refactored into two separate lints: /// cast_ptr_alignment and transmute_ptr_to_ptr. @@ -70,9 +82,11 @@ declare_deprecated_lint! { } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy. + /// ### Deprecation reason + /// This lint is too subjective, not having a good reason for being in clippy. /// Additionally, compound assignment operators may be overloaded separately from their non-assigning /// counterparts, so this lint may suggest a change in behavior or the code may not compile. pub ASSIGN_OPS, @@ -80,9 +94,11 @@ declare_deprecated_lint! { } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** The original rule will only lint for `if let`. After + /// ### Deprecation reason + /// The original rule will only lint for `if let`. After /// making it support to lint `match`, naming as `if let` is not suitable for it. /// So, this lint is deprecated. pub IF_LET_REDUNDANT_PATTERN_MATCHING, @@ -90,9 +106,11 @@ declare_deprecated_lint! { } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This lint used to suggest replacing `let mut vec = + /// ### Deprecation reason + /// This lint used to suggest replacing `let mut vec = /// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The /// replacement has very different performance characteristics so the lint is /// deprecated. @@ -101,51 +119,63 @@ declare_deprecated_lint! { } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This lint has been superseded by #[must_use] in rustc. + /// ### Deprecation reason + /// This lint has been superseded by #[must_use] in rustc. pub UNUSED_COLLECT, "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** Associated-constants are now preferred. + /// ### Deprecation reason + /// Associated-constants are now preferred. pub REPLACE_CONSTS, "associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** The regex! macro does not exist anymore. + /// ### Deprecation reason + /// The regex! macro does not exist anymore. pub REGEX_MACRO, "the regex! macro has been removed from the regex crate in 2018" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This lint has been replaced by `manual_find_map`, a + /// ### Deprecation reason + /// This lint has been replaced by `manual_find_map`, a /// more specific lint. pub FIND_MAP, "this lint has been replaced by `manual_find_map`, a more specific lint" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** This lint has been replaced by `manual_filter_map`, a + /// ### Deprecation reason + /// This lint has been replaced by `manual_filter_map`, a /// more specific lint. pub FILTER_MAP, "this lint has been replaced by `manual_filter_map`, a more specific lint" } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** The `avoid_breaking_exported_api` config option was added, which + /// ### Deprecation reason + /// The `avoid_breaking_exported_api` config option was added, which /// enables the `enum_variant_names` lint for public items. /// ``` pub PUB_ENUM_VARIANT_NAMES, @@ -153,9 +183,11 @@ declare_deprecated_lint! { } declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. + /// ### What it does + /// Nothing. This lint has been deprecated. /// - /// **Deprecation reason:** The `avoid_breaking_exported_api` config option was added, which + /// ### Deprecation reason + /// The `avoid_breaking_exported_api` config option was added, which /// enables the `wrong_self_conversion` lint for public items. pub WRONG_PUB_SELF_CONVENTION, "set the `avoid-breaking-exported-api` config option to `false` to enable the `wrong_self_convention` lint for public items" diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 682003f9c2c..ded7001ad8c 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -11,12 +11,14 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{symbol::sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for explicit `deref()` or `deref_mut()` method calls. + /// ### What it does + /// Checks for explicit `deref()` or `deref_mut()` method calls. /// - /// **Why is this bad?** Dereferencing by `&*x` or `&mut *x` is clearer and more concise, + /// ### Why is this bad? + /// Dereferencing by `&*x` or `&mut *x` is clearer and more concise, /// when not part of a method chain. /// - /// **Example:** + /// ### Example /// ```rust /// use std::ops::Deref; /// let a: &mut String = &mut String::from("foo"); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 7aafaf71383..dcfa5253f83 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -15,10 +15,12 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for deriving `Hash` but implementing `PartialEq` + /// ### What it does + /// Checks for deriving `Hash` but implementing `PartialEq` /// explicitly or vice versa. /// - /// **Why is this bad?** The implementation of these traits must agree (for + /// ### Why is this bad? + /// The implementation of these traits must agree (for /// example for use with `HashMap`) so it’s probably a bad idea to use a /// default-generated `Hash` implementation with an explicitly defined /// `PartialEq`. In particular, the following must hold for any type: @@ -27,9 +29,7 @@ declare_clippy_lint! { /// k1 == k2 ⇒ hash(k1) == hash(k2) /// ``` /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// #[derive(Hash)] /// struct Foo; @@ -44,10 +44,12 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for deriving `Ord` but implementing `PartialOrd` + /// ### What it does + /// Checks for deriving `Ord` but implementing `PartialOrd` /// explicitly or vice versa. /// - /// **Why is this bad?** The implementation of these traits must agree (for + /// ### Why is this bad? + /// The implementation of these traits must agree (for /// example for use with `sort`) so it’s probably a bad idea to use a /// default-generated `Ord` implementation with an explicitly defined /// `PartialOrd`. In particular, the following must hold for any type @@ -57,10 +59,7 @@ declare_clippy_lint! { /// k1.cmp(&k2) == k1.partial_cmp(&k2).unwrap() /// ``` /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// #[derive(Ord, PartialEq, Eq)] /// struct Foo; @@ -95,18 +94,21 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for explicit `Clone` implementations for `Copy` + /// ### What it does + /// Checks for explicit `Clone` implementations for `Copy` /// types. /// - /// **Why is this bad?** To avoid surprising behaviour, these traits should + /// ### Why is this bad? + /// To avoid surprising behaviour, these traits should /// agree and the behaviour of `Copy` cannot be overridden. In almost all /// situations a `Copy` type should have a `Clone` implementation that does /// nothing more than copy the object, which is what `#[derive(Copy, Clone)]` /// gets you. /// - /// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925 + /// ### Known problems + /// Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925 /// - /// **Example:** + /// ### Example /// ```rust,ignore /// #[derive(Copy)] /// struct Foo; @@ -121,16 +123,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for deriving `serde::Deserialize` on a type that + /// ### What it does + /// Checks for deriving `serde::Deserialize` on a type that /// has methods using `unsafe`. /// - /// **Why is this bad?** Deriving `serde::Deserialize` will create a constructor + /// ### Why is this bad? + /// Deriving `serde::Deserialize` will create a constructor /// that may violate invariants hold by another constructor. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// use serde::Deserialize; /// diff --git a/clippy_lints/src/disallowed_method.rs b/clippy_lints/src/disallowed_method.rs index aa1a609afed..7069cb4198c 100644 --- a/clippy_lints/src/disallowed_method.rs +++ b/clippy_lints/src/disallowed_method.rs @@ -8,15 +8,14 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Symbol; declare_clippy_lint! { - /// **What it does:** Denies the configured methods and functions in clippy.toml + /// ### What it does + /// Denies the configured methods and functions in clippy.toml /// - /// **Why is this bad?** Some methods are undesirable in certain contexts, + /// ### Why is this bad? + /// Some methods are undesirable in certain contexts, /// and it's beneficial to lint for them as needed. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// An example clippy.toml configuration: /// ```toml /// # clippy.toml diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index 12c525634c5..6d38d30cd0b 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -6,7 +6,8 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use unicode_script::{Script, UnicodeScript}; declare_clippy_lint! { - /// **What it does:** Checks for usage of unicode scripts other than those explicitly allowed + /// ### What it does + /// Checks for usage of unicode scripts other than those explicitly allowed /// by the lint config. /// /// This lint doesn't take into account non-text scripts such as `Unknown` and `Linear_A`. @@ -19,7 +20,8 @@ declare_clippy_lint! { /// [aliases]: http://www.unicode.org/reports/tr24/tr24-31.html#Script_Value_Aliases /// [supported_scripts]: https://www.unicode.org/iso15924/iso15924-codes.html /// - /// **Why is this bad?** It may be not desired to have many different scripts for + /// ### Why is this bad? + /// It may be not desired to have many different scripts for /// identifiers in the codebase. /// /// Note that if you only want to allow plain English, you might want to use @@ -27,9 +29,7 @@ declare_clippy_lint! { /// /// [`non_ascii_idents`]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#non-ascii-idents /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Assuming that `clippy.toml` contains the following line: /// // allowed-locales = ["Latin", "Cyrillic"] diff --git a/clippy_lints/src/disallowed_type.rs b/clippy_lints/src/disallowed_type.rs index 7c76e2322c2..e627168b932 100644 --- a/clippy_lints/src/disallowed_type.rs +++ b/clippy_lints/src/disallowed_type.rs @@ -9,14 +9,13 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{Span, Symbol}; declare_clippy_lint! { - /// **What it does:** Denies the configured types in clippy.toml. + /// ### What it does + /// Denies the configured types in clippy.toml. /// - /// **Why is this bad?** Some types are undesirable in certain contexts. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Some types are undesirable in certain contexts. /// + /// ### Example: /// An example clippy.toml configuration: /// ```toml /// # clippy.toml diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 0c19988a975..c39829fdc7a 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -30,15 +30,18 @@ use std::thread; use url::Url; declare_clippy_lint! { - /// **What it does:** Checks for the presence of `_`, `::` or camel-case words + /// ### What it does + /// Checks for the presence of `_`, `::` or camel-case words /// outside ticks in documentation. /// - /// **Why is this bad?** *Rustdoc* supports markdown formatting, `_`, `::` and + /// ### Why is this bad? + /// *Rustdoc* supports markdown formatting, `_`, `::` and /// camel-case probably indicates some code which should be included between /// ticks. `_` can also be used for emphasis in markdown, this lint tries to /// consider that. /// - /// **Known problems:** Lots of bad docs won’t be fixed, what the lint checks + /// ### Known problems + /// Lots of bad docs won’t be fixed, what the lint checks /// for is limited, and there are still false positives. HTML elements and their /// content are not linted. /// @@ -47,7 +50,7 @@ declare_clippy_lint! { /// `[`SmallVec<[T; INLINE_CAPACITY]>`]` and then [`SmallVec<[T; INLINE_CAPACITY]>`]: SmallVec /// would fail. /// - /// **Examples:** + /// ### Examples /// ```rust /// /// Do something with the foo_bar parameter. See also /// /// that::other::module::foo. @@ -68,15 +71,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the doc comments of publicly visible + /// ### What it does + /// Checks for the doc comments of publicly visible /// unsafe functions and warns if there is no `# Safety` section. /// - /// **Why is this bad?** Unsafe functions should document their safety + /// ### Why is this bad? + /// Unsafe functions should document their safety /// preconditions, so that users can be sure they are using them safely. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ```rust ///# type Universe = (); /// /// This function should really be documented @@ -102,16 +105,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks the doc comments of publicly visible functions that + /// ### What it does + /// Checks the doc comments of publicly visible functions that /// return a `Result` type and warns if there is no `# Errors` section. /// - /// **Why is this bad?** Documenting the type of errors that can be returned from a + /// ### Why is this bad? + /// Documenting the type of errors that can be returned from a /// function can help callers write code to handle the errors appropriately. /// - /// **Known problems:** None. - /// - /// **Examples:** - /// + /// ### Examples /// Since the following function returns a `Result` it has an `# Errors` section in /// its doc comment: /// @@ -131,16 +133,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks the doc comments of publicly visible functions that + /// ### What it does + /// Checks the doc comments of publicly visible functions that /// may panic and warns if there is no `# Panics` section. /// - /// **Why is this bad?** Documenting the scenarios in which panicking occurs + /// ### Why is this bad? + /// Documenting the scenarios in which panicking occurs /// can help callers who do not want to panic to avoid those situations. /// - /// **Known problems:** None. - /// - /// **Examples:** - /// + /// ### Examples /// Since the following function may panic it has a `# Panics` section in /// its doc comment: /// @@ -162,14 +163,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `fn main() { .. }` in doctests + /// ### What it does + /// Checks for `fn main() { .. }` in doctests /// - /// **Why is this bad?** The test can be shorter (and likely more readable) + /// ### Why is this bad? + /// The test can be shorter (and likely more readable) /// if the `fn main()` is left implicit. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ``````rust /// /// An example of a doctest with a `main()` function /// /// diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 4966638cb1b..6520bb91faf 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -10,14 +10,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for double comparisons that could be simplified to a single expression. + /// ### What it does + /// Checks for double comparisons that could be simplified to a single expression. /// /// - /// **Why is this bad?** Readability. + /// ### Why is this bad? + /// Readability. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// # let y = 2; diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index e4e4a93b011..d0d87b6df9a 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -4,14 +4,14 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for unnecessary double parentheses. + /// ### What it does + /// Checks for unnecessary double parentheses. /// - /// **Why is this bad?** This makes code harder to read and might indicate a + /// ### Why is this bad? + /// This makes code harder to read and might indicate a /// mistake. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// fn simple_double_parens() -> i32 { diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index b5b29760636..0f3dc866afb 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -8,17 +8,17 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::drop` with a reference + /// ### What it does + /// Checks for calls to `std::mem::drop` with a reference /// instead of an owned value. /// - /// **Why is this bad?** Calling `drop` on a reference will only drop the + /// ### Why is this bad? + /// Calling `drop` on a reference will only drop the /// reference itself, which is a no-op. It will not call the `drop` method (from /// the `Drop` trait implementation) on the underlying referenced value, which /// is likely what was intended. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// let mut lock_guard = mutex.lock(); /// std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex @@ -31,17 +31,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::forget` with a reference + /// ### What it does + /// Checks for calls to `std::mem::forget` with a reference /// instead of an owned value. /// - /// **Why is this bad?** Calling `forget` on a reference will only forget the + /// ### Why is this bad? + /// Calling `forget` on a reference will only forget the /// reference itself, which is a no-op. It will not forget the underlying /// referenced /// value, which is likely what was intended. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = Box::new(1); /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped @@ -52,16 +52,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::drop` with a value + /// ### What it does + /// Checks for calls to `std::mem::drop` with a value /// that derives the Copy trait /// - /// **Why is this bad?** Calling `std::mem::drop` [does nothing for types that + /// ### Why is this bad? + /// Calling `std::mem::drop` [does nothing for types that /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the /// value will be copied and moved into the function on invocation. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x: i32 = 42; // i32 implements Copy /// std::mem::drop(x) // A copy of x is passed to the function, leaving the @@ -73,10 +73,12 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::forget` with a value that + /// ### What it does + /// Checks for calls to `std::mem::forget` with a value that /// derives the Copy trait /// - /// **Why is this bad?** Calling `std::mem::forget` [does nothing for types that + /// ### Why is this bad? + /// Calling `std::mem::forget` [does nothing for types that /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the /// value will be copied and moved into the function on invocation. /// @@ -86,9 +88,7 @@ declare_clippy_lint! { /// there /// is nothing for `std::mem::forget` to ignore. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x: i32 = 42; // i32 implements Copy /// std::mem::forget(x) // A copy of x is passed to the function, leaving the diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 94b09bf7173..3774de62521 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -12,15 +12,15 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::paths; declare_clippy_lint! { - /// **What it does:** Checks for calculation of subsecond microseconds or milliseconds + /// ### What it does + /// Checks for calculation of subsecond microseconds or milliseconds /// from other `Duration` methods. /// - /// **Why is this bad?** It's more concise to call `Duration::subsec_micros()` or + /// ### Why is this bad? + /// It's more concise to call `Duration::subsec_micros()` or /// `Duration::subsec_millis()` than to calculate them. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use std::time::Duration; /// let dur = Duration::new(5, 0); diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index 26984df9539..0541ac5eccc 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -7,14 +7,14 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for usage of if expressions with an `else if` branch, + /// ### What it does + /// Checks for usage of if expressions with an `else if` branch, /// but without a final `else` branch. /// - /// **Why is this bad?** Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10). + /// ### Why is this bad? + /// Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10). /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # fn a() {} /// # fn b() {} diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index c92984a9834..3453c2da278 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -6,13 +6,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `enum`s with no variants. + /// ### What it does + /// Checks for `enum`s with no variants. /// /// As of this writing, the `never_type` is still a /// nightly-only experimental API. Therefore, this lint is only triggered /// if the `never_type` is enabled. /// - /// **Why is this bad?** If you want to introduce a type which + /// ### Why is this bad? + /// If you want to introduce a type which /// can't be instantiated, you should use `!` (the primitive type "never"), /// or a wrapper around it, because `!` has more extensive /// compiler support (type inference, etc...) and wrappers @@ -20,10 +22,7 @@ declare_clippy_lint! { /// For further information visit [never type documentation](https://doc.rust-lang.org/std/primitive.never.html) /// /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// Bad: /// ```rust /// enum Test {} diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 2eb8b1422ed..e1d0d65edb1 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -16,12 +16,15 @@ use rustc_span::{Span, SyntaxContext, DUMMY_SP}; use std::fmt::Write; declare_clippy_lint! { - /// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap` + /// ### What it does + /// Checks for uses of `contains_key` + `insert` on `HashMap` /// or `BTreeMap`. /// - /// **Why is this bad?** Using `entry` is more efficient. + /// ### Why is this bad? + /// Using `entry` is more efficient. /// - /// **Known problems:** The suggestion may have type inference errors in some cases. e.g. + /// ### Known problems + /// The suggestion may have type inference errors in some cases. e.g. /// ```rust /// let mut map = std::collections::HashMap::new(); /// let _ = if !map.contains_key(&0) { @@ -31,7 +34,7 @@ declare_clippy_lint! { /// }; /// ``` /// - /// **Example:** + /// ### Example /// ```rust /// # use std::collections::HashMap; /// # let mut map = HashMap::new(); diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 021136ac5e0..a2c3c7a7b49 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -11,15 +11,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::convert::TryFrom; declare_clippy_lint! { - /// **What it does:** Checks for C-like enumerations that are + /// ### What it does + /// Checks for C-like enumerations that are /// `repr(isize/usize)` and have values that don't fit into an `i32`. /// - /// **Why is this bad?** This will truncate the variant value on 32 bit + /// ### Why is this bad? + /// This will truncate the variant value on 32 bit /// architectures, but works fine on 64 bit. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # #[cfg(target_pointer_width = "64")] /// #[repr(usize)] diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index b1a105a51c1..32b95745b64 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -10,15 +10,15 @@ use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; declare_clippy_lint! { - /// **What it does:** Detects enumeration variants that are prefixed or suffixed + /// ### What it does + /// Detects enumeration variants that are prefixed or suffixed /// by the same characters. /// - /// **Why is this bad?** Enumeration variant names should specify their variant, + /// ### Why is this bad? + /// Enumeration variant names should specify their variant, /// not repeat the enumeration name. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// enum Cake { /// BlackForestCake, @@ -40,14 +40,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Detects type names that are prefixed or suffixed by the + /// ### What it does + /// Detects type names that are prefixed or suffixed by the /// containing module's name. /// - /// **Why is this bad?** It requires the user to type the module name twice. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// It requires the user to type the module name twice. /// - /// **Example:** + /// ### Example /// ```rust /// mod cake { /// struct BlackForestCake; @@ -65,10 +65,12 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for modules that have the same name as their + /// ### What it does + /// Checks for modules that have the same name as their /// parent module /// - /// **Why is this bad?** A typical beginner mistake is to have `mod foo;` and + /// ### Why is this bad? + /// A typical beginner mistake is to have `mod foo;` and /// again `mod foo { .. /// }` in `foo.rs`. /// The expectation is that items inside the inner `mod foo { .. }` are then @@ -78,9 +80,7 @@ declare_clippy_lint! { /// If this is done on purpose, it would be better to choose a more /// representative module name. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// // lib.rs /// mod foo; diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index d39cabfb282..51d5094e8c9 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -9,18 +9,21 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for equal operands to comparison, logical and + /// ### What it does + /// Checks for equal operands to comparison, logical and /// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`, /// `||`, `&`, `|`, `^`, `-` and `/`). /// - /// **Why is this bad?** This is usually just a typo or a copy and paste error. + /// ### Why is this bad? + /// This is usually just a typo or a copy and paste error. /// - /// **Known problems:** False negatives: We had some false positives regarding + /// ### Known problems + /// False negatives: We had some false positives regarding /// calls (notably [racer](https://github.com/phildawes/racer) had one instance /// of `x.pop() && x.pop()`), so we removed matching any function or method /// calls. We may introduce a list of known pure functions in the future. /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// if x + 1 == x + 1 {} @@ -37,15 +40,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for arguments to `==` which have their address + /// ### What it does + /// Checks for arguments to `==` which have their address /// taken to satisfy a bound /// and suggests to dereference the other argument instead /// - /// **Why is this bad?** It is more idiomatic to dereference the other argument. + /// ### Why is this bad? + /// It is more idiomatic to dereference the other argument. /// - /// **Known problems:** None + /// ### Known problems + /// None /// - /// **Example:** + /// ### Example /// ```ignore /// // Bad /// &x == y diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index 4aa9c25b1b0..026d14d0ea2 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -6,15 +6,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for erasing operations, e.g., `x * 0`. + /// ### What it does + /// Checks for erasing operations, e.g., `x * 0`. /// - /// **Why is this bad?** The whole expression can be replaced by zero. + /// ### Why is this bad? + /// The whole expression can be replaced by zero. /// This is most likely not the intended outcome and should probably be /// corrected /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = 1; /// 0 / x; diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 5f400d079da..8b0e9e6bc9b 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -19,16 +19,16 @@ pub struct BoxedLocal { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `Box` where an unboxed `T` would + /// ### What it does + /// Checks for usage of `Box` where an unboxed `T` would /// work fine. /// - /// **Why is this bad?** This is an unnecessary allocation, and bad for + /// ### Why is this bad? + /// This is an unnecessary allocation, and bad for /// performance. It is only necessary to allocate if you wish to move the box /// into something. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # fn foo(bar: usize) {} /// // Bad diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 667eb8eb283..192b69e18f9 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -14,19 +14,22 @@ use rustc_middle::ty::{self, ClosureKind, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for closures which just call another function where + /// ### What it does + /// Checks for closures which just call another function where /// the function can be called directly. `unsafe` functions or calls where types /// get adjusted are ignored. /// - /// **Why is this bad?** Needlessly creating a closure adds code for no benefit + /// ### Why is this bad? + /// Needlessly creating a closure adds code for no benefit /// and gives the optimizer more work. /// - /// **Known problems:** If creating the closure inside the closure has a side- + /// ### Known problems + /// If creating the closure inside the closure has a side- /// effect then moving the closure creation out will change when that side- /// effect runs. /// See [#1439](https://github.com/rust-lang/rust-clippy/issues/1439) for more details. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// xs.map(|x| foo(x)) @@ -42,17 +45,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for closures which only invoke a method on the closure + /// ### What it does + /// Checks for closures which only invoke a method on the closure /// argument and can be replaced by referencing the method directly. /// - /// **Why is this bad?** It's unnecessary to create the closure. + /// ### Why is this bad? + /// It's unnecessary to create the closure. /// - /// **Known problems:** [#3071](https://github.com/rust-lang/rust-clippy/issues/3071), + /// ### Known problems + /// [#3071](https://github.com/rust-lang/rust-clippy/issues/3071), /// [#3942](https://github.com/rust-lang/rust-clippy/issues/3942), /// [#4002](https://github.com/rust-lang/rust-clippy/issues/4002) /// /// - /// **Example:** + /// ### Example /// ```rust,ignore /// Some('a').map(|s| s.to_uppercase()); /// ``` diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 03a8b40df55..f72a1e446d5 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -9,17 +9,20 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for a read and a write to the same variable where + /// ### What it does + /// Checks for a read and a write to the same variable where /// whether the read occurs before or after the write depends on the evaluation /// order of sub-expressions. /// - /// **Why is this bad?** It is often confusing to read. In addition, the + /// ### Why is this bad? + /// It is often confusing to read. In addition, the /// sub-expression evaluation order for Rust is not well documented. /// - /// **Known problems:** Code which intentionally depends on the evaluation + /// ### Known problems + /// Code which intentionally depends on the evaluation /// order, or which is correct for any evaluation order. /// - /// **Example:** + /// ### Example /// ```rust /// let mut x = 0; /// @@ -43,16 +46,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for diverging calls that are not match arms or + /// ### What it does + /// Checks for diverging calls that are not match arms or /// statements. /// - /// **Why is this bad?** It is often confusing to read. In addition, the + /// ### Why is this bad? + /// It is often confusing to read. In addition, the /// sub-expression evaluation order for Rust is not well documented. /// - /// **Known problems:** Someone might want to use `some_bool || panic!()` as a + /// ### Known problems + /// Someone might want to use `some_bool || panic!()` as a /// shorthand. /// - /// **Example:** + /// ### Example /// ```rust,no_run /// # fn b() -> bool { true } /// # fn c() -> bool { true } diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 4e2dbf005d5..476e6d23f12 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -8,19 +8,19 @@ use rustc_span::{sym, Span}; use std::convert::TryInto; declare_clippy_lint! { - /// **What it does:** Checks for excessive + /// ### What it does + /// Checks for excessive /// use of bools in structs. /// - /// **Why is this bad?** Excessive bools in a struct + /// ### Why is this bad? + /// Excessive bools in a struct /// is often a sign that it's used as a state machine, /// which is much better implemented as an enum. /// If it's not the case, excessive bools usually benefit /// from refactoring into two-variant enums for better /// readability and API. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust /// struct S { @@ -44,19 +44,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for excessive use of + /// ### What it does + /// Checks for excessive use of /// bools in function definitions. /// - /// **Why is this bad?** Calls to such functions + /// ### Why is this bad? + /// Calls to such functions /// are confusing and error prone, because it's /// hard to remember argument order and you have /// no type system support to back you up. Using /// two-variant enums instead of bools often makes /// API easier to use. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// fn f(is_round: bool, is_hot: bool) { ... } diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index 60ad2e8ee14..e00126046c0 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -8,16 +8,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Warns on any exported `enum`s that are not tagged `#[non_exhaustive]` + /// ### What it does + /// Warns on any exported `enum`s that are not tagged `#[non_exhaustive]` /// - /// **Why is this bad?** Exhaustive enums are typically fine, but a project which does + /// ### Why is this bad? + /// Exhaustive enums are typically fine, but a project which does /// not wish to make a stability commitment around exported enums may wish to /// disable them by default. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// enum Foo { /// Bar, @@ -38,16 +37,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns on any exported `structs`s that are not tagged `#[non_exhaustive]` + /// ### What it does + /// Warns on any exported `structs`s that are not tagged `#[non_exhaustive]` /// - /// **Why is this bad?** Exhaustive structs are typically fine, but a project which does + /// ### Why is this bad? + /// Exhaustive structs are typically fine, but a project which does /// not wish to make a stability commitment around exported structs may wish to /// disable them by default. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct Foo { /// bar: u8, diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 16246e548b6..9cd5b2d9f44 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -6,15 +6,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** `exit()` terminates the program and doesn't provide a + /// ### What it does + /// `exit()` terminates the program and doesn't provide a /// stack trace. /// - /// **Why is this bad?** Ideally a program is terminated by finishing + /// ### Why is this bad? + /// Ideally a program is terminated by finishing /// the main function. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// std::process::exit(0) /// ``` diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 66724294804..4f46ef906f4 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -9,14 +9,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for usage of `write!()` / `writeln()!` which can be + /// ### What it does + /// Checks for usage of `write!()` / `writeln()!` which can be /// replaced with `(e)print!()` / `(e)println!()` /// - /// **Why is this bad?** Using `(e)println! is clearer and more concise + /// ### Why is this bad? + /// Using `(e)println! is clearer and more concise /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use std::io::Write; /// # let bar = "furchtbar"; diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 2937fcb9ca0..7e4d1b3ef9f 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -10,13 +10,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for impls of `From<..>` that contain `panic!()` or `unwrap()` + /// ### What it does + /// Checks for impls of `From<..>` that contain `panic!()` or `unwrap()` /// - /// **Why is this bad?** `TryFrom` should be used if there's a possibility of failure. + /// ### Why is this bad? + /// `TryFrom` should be used if there's a possibility of failure. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// struct Foo(i32); /// diff --git a/clippy_lints/src/float_equality_without_abs.rs b/clippy_lints/src/float_equality_without_abs.rs index 1e503cc795c..c33d80b8e8e 100644 --- a/clippy_lints/src/float_equality_without_abs.rs +++ b/clippy_lints/src/float_equality_without_abs.rs @@ -11,30 +11,32 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; declare_clippy_lint! { - /// **What it does:** Checks for statements of the form `(a - b) < f32::EPSILON` or - /// `(a - b) < f64::EPSILON`. Notes the missing `.abs()`. - /// - /// **Why is this bad?** The code without `.abs()` is more likely to have a bug. - /// - /// **Known problems:** If the user can ensure that b is larger than a, the `.abs()` is - /// technically unneccessary. However, it will make the code more robust and doesn't have any - /// large performance implications. If the abs call was deliberately left out for performance - /// reasons, it is probably better to state this explicitly in the code, which then can be done - /// with an allow. - /// - /// **Example:** - /// - /// ```rust - /// pub fn is_roughly_equal(a: f32, b: f32) -> bool { - /// (a - b) < f32::EPSILON - /// } - /// ``` - /// Use instead: - /// ```rust - /// pub fn is_roughly_equal(a: f32, b: f32) -> bool { - /// (a - b).abs() < f32::EPSILON - /// } - /// ``` + /// ### What it does + /// Checks for statements of the form `(a - b) < f32::EPSILON` or + /// `(a - b) < f64::EPSILON`. Notes the missing `.abs()`. + /// + /// ### Why is this bad? + /// The code without `.abs()` is more likely to have a bug. + /// + /// ### Known problems + /// If the user can ensure that b is larger than a, the `.abs()` is + /// technically unneccessary. However, it will make the code more robust and doesn't have any + /// large performance implications. If the abs call was deliberately left out for performance + /// reasons, it is probably better to state this explicitly in the code, which then can be done + /// with an allow. + /// + /// ### Example + /// ```rust + /// pub fn is_roughly_equal(a: f32, b: f32) -> bool { + /// (a - b) < f32::EPSILON + /// } + /// ``` + /// Use instead: + /// ```rust + /// pub fn is_roughly_equal(a: f32, b: f32) -> bool { + /// (a - b).abs() < f32::EPSILON + /// } + /// ``` pub FLOAT_EQUALITY_WITHOUT_ABS, suspicious, "float equality check without `.abs()`" diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 7968e7b764d..a3d70f31f00 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -10,15 +10,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::fmt; declare_clippy_lint! { - /// **What it does:** Checks for float literals with a precision greater + /// ### What it does + /// Checks for float literals with a precision greater /// than that supported by the underlying type. /// - /// **Why is this bad?** Rust will truncate the literal silently. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Rust will truncate the literal silently. /// + /// ### Example /// ```rust /// // Bad /// let v: f32 = 0.123_456_789_9; @@ -34,16 +33,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for whole number float literals that + /// ### What it does + /// Checks for whole number float literals that /// cannot be represented as the underlying type without loss. /// - /// **Why is this bad?** Rust will silently lose precision during + /// ### Why is this bad? + /// Rust will silently lose precision during /// conversion to a float. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let _: f32 = 16_777_217.0; // 16_777_216.0 diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index e38384b01d4..b01c0cdd846 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -18,16 +18,15 @@ use std::f64::consts as f64_consts; use sugg::Sugg; declare_clippy_lint! { - /// **What it does:** Looks for floating-point expressions that + /// ### What it does + /// Looks for floating-point expressions that /// can be expressed using built-in methods to improve accuracy /// at the cost of performance. /// - /// **Why is this bad?** Negatively impacts accuracy. - /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Why is this bad? + /// Negatively impacts accuracy. /// + /// ### Example /// ```rust /// let a = 3f32; /// let _ = a.powf(1.0 / 3.0); @@ -49,16 +48,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Looks for floating-point expressions that + /// ### What it does + /// Looks for floating-point expressions that /// can be expressed using built-in methods to improve both /// accuracy and performance. /// - /// **Why is this bad?** Negatively impacts accuracy and performance. - /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Why is this bad? + /// Negatively impacts accuracy and performance. /// + /// ### Example /// ```rust /// use std::f32::consts::E; /// diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index ca3490d8eda..863c606f5a9 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -13,18 +13,18 @@ use rustc_span::symbol::kw; use rustc_span::{sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for the use of `format!("string literal with no + /// ### What it does + /// Checks for the use of `format!("string literal with no /// argument")` and `format!("{}", foo)` where `foo` is a string. /// - /// **Why is this bad?** There is no point of doing that. `format!("foo")` can + /// ### Why is this bad? + /// There is no point of doing that. `format!("foo")` can /// be replaced by `"foo".to_owned()` if you really need a `String`. The even /// worse `&format!("foo")` is often encountered in the wild. `format!("{}", /// foo)` can be replaced by `foo.clone()` if `foo: String` or `foo.to_owned()` /// if `foo: &str`. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ```rust /// /// // Bad diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 8aefb8d46f6..b4cf1971d78 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -9,15 +9,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for use of the non-existent `=*`, `=!` and `=-` + /// ### What it does + /// Checks for use of the non-existent `=*`, `=!` and `=-` /// operators. /// - /// **Why is this bad?** This is either a typo of `*=`, `!=` or `-=` or + /// ### Why is this bad? + /// This is either a typo of `*=`, `!=` or `-=` or /// confusing. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// a =- 42; // confusing, should it be `a -= 42` or `a = -42`? /// ``` @@ -27,15 +27,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks the formatting of a unary operator on the right hand side + /// ### What it does + /// Checks the formatting of a unary operator on the right hand side /// of a binary operator. It lints if there is no space between the binary and unary operators, /// but there is a space between the unary and its operand. /// - /// **Why is this bad?** This is either a typo in the binary operator or confusing. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This is either a typo in the binary operator or confusing. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// if foo <- 30 { // this should be `foo < -30` but looks like a different operator /// } @@ -49,15 +49,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for formatting of `else`. It lints if the `else` + /// ### What it does + /// Checks for formatting of `else`. It lints if the `else` /// is followed immediately by a newline or the `else` seems to be missing. /// - /// **Why is this bad?** This is probably some refactoring remnant, even if the + /// ### Why is this bad? + /// This is probably some refactoring remnant, even if the /// code is correct, it might look confusing. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// if foo { /// } { // looks like an `else` is missing here @@ -85,14 +85,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for possible missing comma in an array. It lints if + /// ### What it does + /// Checks for possible missing comma in an array. It lints if /// an array element is a binary operator expression and it lies on two lines. /// - /// **Why is this bad?** This could lead to unexpected results. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This could lead to unexpected results. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// let a = &[ /// -1, -2, -3 // <= no comma here diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 48316c3a61d..623546cd1de 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -8,14 +8,13 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** Searches for implementations of the `Into<..>` trait and suggests to implement `From<..>` instead. + /// ### What it does + /// Searches for implementations of the `Into<..>` trait and suggests to implement `From<..>` instead. /// - /// **Why is this bad?** According the std docs implementing `From<..>` is preferred since it gives you `Into<..>` for free where the reverse isn't true. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// According the std docs implementing `From<..>` is preferred since it gives you `Into<..>` for free where the reverse isn't true. /// + /// ### Example /// ```rust /// struct StringWrapper(String); /// diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index 3da5bc95b6d..cc4bb85c50f 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -10,20 +10,22 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** + /// ### What it does + /// /// Checks for function invocations of the form `primitive::from_str_radix(s, 10)` /// - /// **Why is this bad?** + /// ### Why is this bad? + /// /// This specific common use case can be rewritten as `s.parse::()` /// (and in most cases, the turbofish can be removed), which reduces code length /// and complexity. /// - /// **Known problems:** + /// ### Known problems + /// /// This lint may suggest using (&).parse() instead of .parse() directly /// in some cases, which is correct but adds unnecessary complexity to the code. /// - /// **Example:** - /// + /// ### Example /// ```ignore /// let input: &str = get_input(); /// let num = u16::from_str_radix(input, 10)?; diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index 2beb9bc94bf..ce23c0ce4a0 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -11,15 +11,15 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for functions with too many parameters. + /// ### What it does + /// Checks for functions with too many parameters. /// - /// **Why is this bad?** Functions with lots of parameters are considered bad + /// ### Why is this bad? + /// Functions with lots of parameters are considered bad /// style and reduce readability (“what does the 5th parameter mean?”). Consider /// grouping some parameters into a new type. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # struct Color; /// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) { @@ -32,16 +32,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for functions with a large amount of lines. + /// ### What it does + /// Checks for functions with a large amount of lines. /// - /// **Why is this bad?** Functions with a lot of lines are harder to understand + /// ### Why is this bad? + /// Functions with a lot of lines are harder to understand /// due to having to look at a larger amount of code to understand what the /// function is doing. Consider splitting the body of the function into /// multiple functions. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn im_too_long() { /// println!(""); @@ -55,15 +55,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for public functions that dereference raw pointer + /// ### What it does + /// Checks for public functions that dereference raw pointer /// arguments but are not marked `unsafe`. /// - /// **Why is this bad?** The function should probably be marked `unsafe`, since + /// ### Why is this bad? + /// The function should probably be marked `unsafe`, since /// for an arbitrary raw pointer, there is no way of telling for sure if it is /// valid. /// - /// **Known problems:** - /// + /// ### Known problems /// * It does not check functions recursively so if the pointer is passed to a /// private non-`unsafe` function which does the dereferencing, the lint won't /// trigger. @@ -71,7 +72,7 @@ declare_clippy_lint! { /// got from an argument in some other way (`fn foo(bar: &[*const u8])` or /// `some_argument.get_raw_ptr()`). /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// pub fn foo(x: *const u8) { @@ -89,17 +90,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for a [`#[must_use]`] attribute on + /// ### What it does + /// Checks for a [`#[must_use]`] attribute on /// unit-returning functions and methods. /// /// [`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute /// - /// **Why is this bad?** Unit values are useless. The attribute is likely + /// ### Why is this bad? + /// Unit values are useless. The attribute is likely /// a remnant of a refactoring that removed the return type. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ```rust /// #[must_use] /// fn useless() { } @@ -110,19 +111,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for a [`#[must_use]`] attribute without + /// ### What it does + /// Checks for a [`#[must_use]`] attribute without /// further information on functions and methods that return a type already /// marked as `#[must_use]`. /// /// [`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute /// - /// **Why is this bad?** The attribute isn't needed. Not using the result + /// ### Why is this bad? + /// The attribute isn't needed. Not using the result /// will already be reported. Alternatively, one can add some text to the /// attribute to improve the lint message. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ```rust /// #[must_use] /// fn double_must_use() -> Result<(), ()> { @@ -135,16 +136,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for public functions that have no + /// ### What it does + /// Checks for public functions that have no /// [`#[must_use]`] attribute, but return something not already marked /// must-use, have no mutable arg and mutate no statics. /// /// [`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute /// - /// **Why is this bad?** Not bad at all, this lint just shows places where + /// ### Why is this bad? + /// Not bad at all, this lint just shows places where /// you could add the attribute. /// - /// **Known problems:** The lint only checks the arguments for mutable + /// ### Known problems + /// The lint only checks the arguments for mutable /// types without looking if they are actually changed. On the other hand, /// it also ignores a broad range of potentially interesting side effects, /// because we cannot decide whether the programmer intends the function to @@ -152,7 +156,7 @@ declare_clippy_lint! { /// positives. At least we don't lint if the result type is unit or already /// `#[must_use]`. /// - /// **Examples:** + /// ### Examples /// ```rust /// // this could be annotated with `#[must_use]`. /// fn id(t: T) -> T { t } @@ -163,20 +167,23 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for public functions that return a `Result` + /// ### What it does + /// Checks for public functions that return a `Result` /// with an `Err` type of `()`. It suggests using a custom type that /// implements `std::error::Error`. /// - /// **Why is this bad?** Unit does not implement `Error` and carries no + /// ### Why is this bad? + /// Unit does not implement `Error` and carries no /// further information about what went wrong. /// - /// **Known problems:** Of course, this lint assumes that `Result` is used + /// ### Known problems + /// Of course, this lint assumes that `Result` is used /// for a fallible operation (which is after all the intended use). However /// code may opt to (mis)use it as a basic two-variant-enum. In that case, /// the suggestion is misguided, and the code should use a custom enum /// instead. /// - /// **Examples:** + /// ### Examples /// ```rust /// pub fn read_u8() -> Result { Err(()) } /// ``` diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 515b8887453..0be03969bcb 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -12,12 +12,14 @@ use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; use rustc_trait_selection::traits::{self, FulfillmentError, TraitEngine}; declare_clippy_lint! { - /// **What it does:** This lint requires Future implementations returned from + /// ### What it does + /// This lint requires Future implementations returned from /// functions and methods to implement the `Send` marker trait. It is mostly /// used by library authors (public and internal) that target an audience where /// multithreaded executors are likely to be used for running these Futures. /// - /// **Why is this bad?** A Future implementation captures some state that it + /// ### Why is this bad? + /// A Future implementation captures some state that it /// needs to eventually produce its final value. When targeting a multithreaded /// executor (which is the norm on non-embedded devices) this means that this /// state may need to be transported to other threads, in other words the @@ -31,10 +33,7 @@ declare_clippy_lint! { /// modifying the library where the offending Future implementation is /// produced. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// async fn not_send(bytes: std::rc::Rc<[u8]>) {} /// ``` diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index 8e45fdfecc4..ced35030de8 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -14,10 +14,12 @@ use rustc_span::source_map::Spanned; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for using `x.get(x.len() - 1)` instead of + /// ### What it does + /// Checks for using `x.get(x.len() - 1)` instead of /// `x.last()`. /// - /// **Why is this bad?** Using `x.last()` is easier to read and has the same + /// ### Why is this bad? + /// Using `x.last()` is easier to read and has the same /// result. /// /// Note that using `x[x.len() - 1]` is semantically different from @@ -27,10 +29,7 @@ declare_clippy_lint! { /// There is another lint (get_unwrap) that covers the case of using /// `x.get(index).unwrap()` instead of `x[index]`. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let x = vec![2, 3, 5]; diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 99c461930e4..5feb0ce8dec 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -11,14 +11,14 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::{clip, unsext}; declare_clippy_lint! { - /// **What it does:** Checks for identity operations, e.g., `x + 0`. + /// ### What it does + /// Checks for identity operations, e.g., `x + 0`. /// - /// **Why is this bad?** This code can be removed without changing the + /// ### Why is this bad? + /// This code can be removed without changing the /// meaning. So it just obscures what's going on. Delete it mercilessly. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// x / 1 + 0 * 1 - 0 | 0; diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index 5403d76ea30..d3ddeda9fd1 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -9,16 +9,15 @@ use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `Mutex::lock` calls in `if let` expression + /// ### What it does + /// Checks for `Mutex::lock` calls in `if let` expression /// with lock calls in any of the else blocks. /// - /// **Why is this bad?** The Mutex lock remains held for the whole + /// ### Why is this bad? + /// The Mutex lock remains held for the whole /// `if let ... else` block and deadlocks. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// if let Ok(thing) = mutex.lock() { /// do_thing(); diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 611da3744ee..587307811a1 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -10,14 +10,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:*** Checks for unnecessary `ok()` in if let. + /// ### What it does + ///* Checks for unnecessary `ok()` in if let. /// - /// **Why is this bad?** Calling `ok()` in if let is unnecessary, instead match + /// ### Why is this bad? + /// Calling `ok()` in if let is unnecessary, instead match /// on `Ok(pat)` /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// for i in iter { /// if let Some(value) = i.parse().ok() { diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index c56f67df061..28db7233d70 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -8,14 +8,14 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for usage of `!` or `!=` in an if condition with an + /// ### What it does + /// Checks for usage of `!` or `!=` in an if condition with an /// else branch. /// - /// **Why is this bad?** Negations reduce the readability of statements. + /// ### Why is this bad? + /// Negations reduce the readability of statements. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let v: Vec = vec![]; /// # fn a() {} diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index eadcd0867a8..17b9a2f888e 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -10,14 +10,13 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for if-else that could be written to `bool::then`. + /// ### What it does + /// Checks for if-else that could be written to `bool::then`. /// - /// **Why is this bad?** Looks a little redundant. Using `bool::then` helps it have less lines of code. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Looks a little redundant. Using `bool::then` helps it have less lines of code. /// + /// ### Example /// ```rust /// # let v = vec![0]; /// let a = if v.is_empty() { diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 879d6a75bbe..aae44f64e66 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -22,18 +22,21 @@ use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::is_type_diagnostic_item; declare_clippy_lint! { - /// **What it does:** Checks for public `impl` or `fn` missing generalization + /// ### What it does + /// Checks for public `impl` or `fn` missing generalization /// over different hashers and implicitly defaulting to the default hashing /// algorithm (`SipHash`). /// - /// **Why is this bad?** `HashMap` or `HashSet` with custom hashers cannot be + /// ### Why is this bad? + /// `HashMap` or `HashSet` with custom hashers cannot be /// used with them. /// - /// **Known problems:** Suggestions for replacing constructors can contain + /// ### Known problems + /// Suggestions for replacing constructors can contain /// false-positives. Also applying suggestions can require modification of other /// pieces of code, possibly including external crates. /// - /// **Example:** + /// ### Example /// ```rust /// # use std::collections::HashMap; /// # use std::hash::{Hash, BuildHasher}; diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index f2f830ca5c0..fa7b5302cb1 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -13,17 +13,17 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{Span, SyntaxContext}; declare_clippy_lint! { - /// **What it does:** Checks for missing return statements at the end of a block. + /// ### What it does + /// Checks for missing return statements at the end of a block. /// - /// **Why is this bad?** Actually omitting the return keyword is idiomatic Rust code. Programmers + /// ### Why is this bad? + /// Actually omitting the return keyword is idiomatic Rust code. Programmers /// coming from other languages might prefer the expressiveness of `return`. It's possible to miss /// the last returning statement because the only difference is a missing `;`. Especially in bigger /// code with multiple return paths having a `return` keyword makes it easier to find the /// corresponding statements. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn foo(x: usize) -> usize { /// x diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 4069a685ea0..0a7d31dce2f 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -8,14 +8,13 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for implicit saturating subtraction. + /// ### What it does + /// Checks for implicit saturating subtraction. /// - /// **Why is this bad?** Simplicity and readability. Instead we can easily use an builtin function. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Simplicity and readability. Instead we can easily use an builtin function. /// + /// ### Example /// ```rust /// let end: u32 = 10; /// let start: u32 = 5; diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 3b635071f28..1f8240a1f63 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -10,11 +10,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::Symbol; declare_clippy_lint! { - /// **What it does:** Checks for struct constructors where all fields are shorthand and + /// ### What it does + /// Checks for struct constructors where all fields are shorthand and /// the order of the field init shorthand in the constructor is inconsistent /// with the order in the struct definition. /// - /// **Why is this bad?** Since the order of fields in a constructor doesn't affect the + /// ### Why is this bad? + /// Since the order of fields in a constructor doesn't affect the /// resulted instance as the below example indicates, /// /// ```rust @@ -32,10 +34,7 @@ declare_clippy_lint! { /// /// inconsistent order can be confusing and decreases readability and consistency. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct Foo { /// x: i32, diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index bfa284f333a..8c1f1073309 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -10,14 +10,17 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for out of bounds array indexing with a constant + /// ### What it does + /// Checks for out of bounds array indexing with a constant /// index. /// - /// **Why is this bad?** This will always panic at runtime. + /// ### Why is this bad? + /// This will always panic at runtime. /// - /// **Known problems:** Hopefully none. + /// ### Known problems + /// Hopefully none. /// - /// **Example:** + /// ### Example /// ```no_run /// # #![allow(const_err)] /// let x = [1, 2, 3, 4]; @@ -36,16 +39,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of indexing or slicing. Arrays are special cases, this lint + /// ### What it does + /// Checks for usage of indexing or slicing. Arrays are special cases, this lint /// does report on arrays if we can tell that slicing operations are in bounds and does not /// lint on constant `usize` indexing on arrays because that is handled by rustc's `const_err` lint. /// - /// **Why is this bad?** Indexing and slicing can panic at runtime and there are + /// ### Why is this bad? + /// Indexing and slicing can panic at runtime and there are /// safe alternatives. /// - /// **Known problems:** Hopefully none. + /// ### Known problems + /// Hopefully none. /// - /// **Example:** + /// ### Example /// ```rust,no_run /// // Vector /// let x = vec![0; 5]; diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 295a4e1fccb..2411a3175b9 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -7,14 +7,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::{sym, Symbol}; declare_clippy_lint! { - /// **What it does:** Checks for iteration that is guaranteed to be infinite. + /// ### What it does + /// Checks for iteration that is guaranteed to be infinite. /// - /// **Why is this bad?** While there may be places where this is acceptable + /// ### Why is this bad? + /// While there may be places where this is acceptable /// (e.g., in event streams), in most cases this is simply an error. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```no_run /// use std::iter; /// @@ -26,15 +26,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for iteration that may be infinite. + /// ### What it does + /// Checks for iteration that may be infinite. /// - /// **Why is this bad?** While there may be places where this is acceptable + /// ### Why is this bad? + /// While there may be places where this is acceptable /// (e.g., in event streams), in most cases this is simply an error. /// - /// **Known problems:** The code may have a condition to stop iteration, but + /// ### Known problems + /// The code may have a condition to stop iteration, but /// this lint is not clever enough to analyze it. /// - /// **Example:** + /// ### Example /// ```rust /// let infinite_iter = 0..; /// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5)); diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 9641784eb9a..d87055c842c 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -10,13 +10,13 @@ use rustc_span::Span; use std::collections::hash_map::Entry; declare_clippy_lint! { - /// **What it does:** Checks for multiple inherent implementations of a struct + /// ### What it does + /// Checks for multiple inherent implementations of a struct /// - /// **Why is this bad?** Splitting the implementation of a type makes the code harder to navigate. + /// ### Why is this bad? + /// Splitting the implementation of a type makes the code harder to navigate. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// struct X; /// impl X { diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index b023e13e846..b62fad4bd39 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -8,14 +8,16 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`. + /// ### What it does + /// Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`. /// - /// **Why is this bad?** This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred. + /// ### Why is this bad? + /// This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred. /// - /// **Known problems:** None - /// - /// ** Example:** + /// ### Known problems + /// None /// + /// ### Example /// ```rust /// // Bad /// pub struct A; @@ -45,14 +47,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String` and if the type implementing this method also implements the `Display` trait. - /// - /// **Why is this bad?** This method is also implicitly defined if a type implements the `Display` trait. The less versatile inherent method will then shadow the implementation introduced by `Display`. + /// ### What it does + /// Checks for the definition of inherent methods with a signature of `to_string(&self) -> String` and if the type implementing this method also implements the `Display` trait. /// - /// **Known problems:** None + /// ### Why is this bad? + /// This method is also implicitly defined if a type implements the `Display` trait. The less versatile inherent method will then shadow the implementation introduced by `Display`. /// - /// ** Example:** + /// ### Known problems + /// None /// + /// ### Example /// ```rust /// // Bad /// use std::fmt; diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 20f00bd51ba..3e3df903f17 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -10,14 +10,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Symbol}; declare_clippy_lint! { - /// **What it does:** Checks for `#[inline]` on trait methods without bodies + /// ### What it does + /// Checks for `#[inline]` on trait methods without bodies /// - /// **Why is this bad?** Only implementations of trait methods may be inlined. + /// ### Why is this bad? + /// Only implementations of trait methods may be inlined. /// The inline attribute is ignored for trait methods without bodies. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// trait Animal { /// #[inline] diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index c4a1222b51f..49b69dd072a 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -8,13 +8,13 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block + /// ### What it does + /// Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block /// - /// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`. + /// ### Why is this bad? + /// Readability -- better to use `> y` instead of `>= y + 1`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// # let y = 1; diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs index e5482f675e7..a0e6f12b812 100644 --- a/clippy_lints/src/integer_division.rs +++ b/clippy_lints/src/integer_division.rs @@ -5,15 +5,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for division of integers + /// ### What it does + /// Checks for division of integers /// - /// **Why is this bad?** When outside of some very specific algorithms, + /// ### Why is this bad? + /// When outside of some very specific algorithms, /// integer division is very often a mistake because it discards the /// remainder. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let x = 3 / 2; diff --git a/clippy_lints/src/invalid_upcast_comparisons.rs b/clippy_lints/src/invalid_upcast_comparisons.rs index 37011f5578d..3b28b121204 100644 --- a/clippy_lints/src/invalid_upcast_comparisons.rs +++ b/clippy_lints/src/invalid_upcast_comparisons.rs @@ -14,18 +14,20 @@ use clippy_utils::source::snippet; use clippy_utils::{comparisons, sext}; declare_clippy_lint! { - /// **What it does:** Checks for comparisons where the relation is always either + /// ### What it does + /// Checks for comparisons where the relation is always either /// true or false, but where one side has been upcast so that the comparison is /// necessary. Only integer types are checked. /// - /// **Why is this bad?** An expression like `let x : u8 = ...; (x as u32) > 300` + /// ### Why is this bad? + /// An expression like `let x : u8 = ...; (x as u32) > 300` /// will mistakenly imply that it is possible for `x` to be outside the range of /// `u8`. /// - /// **Known problems:** + /// ### Known problems /// https://github.com/rust-lang/rust-clippy/issues/886 /// - /// **Example:** + /// ### Example /// ```rust /// let x: u8 = 1; /// (x as u32) > 300; diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index c69571f32a2..429c6ed7d2d 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -7,15 +7,15 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for items declared after some statement in a block. + /// ### What it does + /// Checks for items declared after some statement in a block. /// - /// **Why is this bad?** Items live for the entire scope they are declared + /// ### Why is this bad? + /// Items live for the entire scope they are declared /// in. But statements are processed in order. This might cause confusion as /// it's hard to figure out which item is meant in a statement. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// fn foo() { diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 48dc5fefe99..5d4e06c2af0 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -11,15 +11,15 @@ use rustc_span::{BytePos, Pos, Span}; use rustc_typeck::hir_ty_to_ty; declare_clippy_lint! { - /// **What it does:** Checks for large `const` arrays that should + /// ### What it does + /// Checks for large `const` arrays that should /// be defined as `static` instead. /// - /// **Why is this bad?** Performance: const variables are inlined upon use. + /// ### Why is this bad? + /// Performance: const variables are inlined upon use. /// Static items result in only one instance and has a fixed location in memory. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// pub const a = [0u32; 1_000_000]; diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index f166748d86b..cde2336b690 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -10,20 +10,22 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_target::abi::LayoutOf; declare_clippy_lint! { - /// **What it does:** Checks for large size differences between variants on + /// ### What it does + /// Checks for large size differences between variants on /// `enum`s. /// - /// **Why is this bad?** Enum size is bounded by the largest variant. Having a + /// ### Why is this bad? + /// Enum size is bounded by the largest variant. Having a /// large variant can penalize the memory layout of that enum. /// - /// **Known problems:** This lint obviously cannot take the distribution of + /// ### Known problems + /// This lint obviously cannot take the distribution of /// variants in your running program into account. It is possible that the /// smaller variants make up less than 1% of all instances, in which case /// the overhead is negligible and the boxing is counter-productive. Always /// measure the change this lint suggests. /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// enum Test { diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index c46b98022c6..7088630bfdb 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -10,13 +10,13 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use crate::rustc_target::abi::LayoutOf; declare_clippy_lint! { - /// **What it does:** Checks for local arrays that may be too large. + /// ### What it does + /// Checks for local arrays that may be too large. /// - /// **Why is this bad?** Large local arrays may cause stack overflow. + /// ### Why is this bad? + /// Large local arrays may cause stack overflow. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// let a = [0u32; 1_000_000]; /// ``` diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 892b3af0b32..b66d7a9f729 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -18,17 +18,17 @@ use rustc_span::{ }; declare_clippy_lint! { - /// **What it does:** Checks for getting the length of something via `.len()` + /// ### What it does + /// Checks for getting the length of something via `.len()` /// just to compare to zero, and suggests using `.is_empty()` where applicable. /// - /// **Why is this bad?** Some structures can answer `.is_empty()` much faster + /// ### Why is this bad? + /// Some structures can answer `.is_empty()` much faster /// than calculating their length. So it is good to get into the habit of using /// `.is_empty()`, and having it is cheap. /// Besides, it makes the intent clearer than a manual comparison in some contexts. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// if x.len() == 0 { /// .. @@ -52,18 +52,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for items that implement `.len()` but not + /// ### What it does + /// Checks for items that implement `.len()` but not /// `.is_empty()`. /// - /// **Why is this bad?** It is good custom to have both methods, because for + /// ### Why is this bad? + /// It is good custom to have both methods, because for /// some data structures, asking about the length will be a costly operation, /// whereas `.is_empty()` can usually answer in constant time. Also it used to /// lead to false positives on the [`len_zero`](#len_zero) lint – currently that /// lint will ignore such entities. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// impl X { /// pub fn len(&self) -> usize { @@ -77,17 +77,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for comparing to an empty slice such as `""` or `[]`, + /// ### What it does + /// Checks for comparing to an empty slice such as `""` or `[]`, /// and suggests using `.is_empty()` where applicable. /// - /// **Why is this bad?** Some structures can answer `.is_empty()` much faster + /// ### Why is this bad? + /// Some structures can answer `.is_empty()` much faster /// than checking for equality. So it is good to get into the habit of using /// `.is_empty()`, and having it is cheap. /// Besides, it makes the intent clearer than a manual comparison in some contexts. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// ```ignore /// if s == "" { diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 67eae4d87bb..13f0d43cf8d 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -9,14 +9,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for variable declarations immediately followed by a + /// ### What it does + /// Checks for variable declarations immediately followed by a /// conditional affectation. /// - /// **Why is this bad?** This is not idiomatic Rust. + /// ### Why is this bad? + /// This is not idiomatic Rust. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// let foo; /// diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index e627b1385bc..8992d25932c 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -9,15 +9,15 @@ use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `let _ = ` + /// ### What it does + /// Checks for `let _ = ` /// where expr is #[must_use] /// - /// **Why is this bad?** It's better to explicitly + /// ### Why is this bad? + /// It's better to explicitly /// handle the value of a #[must_use] expr /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn f() -> Result { /// Ok(0) @@ -33,17 +33,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `let _ = sync_lock` + /// ### What it does + /// Checks for `let _ = sync_lock` /// - /// **Why is this bad?** This statement immediately drops the lock instead of + /// ### Why is this bad? + /// This statement immediately drops the lock instead of /// extending its lifetime to the end of the scope, which is often not intended. /// To extend lock lifetime to the end of the scope, use an underscore-prefixed /// name instead (i.e. _lock). If you want to explicitly drop the lock, /// `std::mem::drop` conveys your intention better and is less error-prone. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// Bad: /// ```rust,ignore @@ -60,19 +60,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `let _ = ` + /// ### What it does + /// Checks for `let _ = ` /// where expr has a type that implements `Drop` /// - /// **Why is this bad?** This statement immediately drops the initializer + /// ### Why is this bad? + /// This statement immediately drops the initializer /// expression instead of extending its lifetime to the end of the scope, which /// is often not intended. To extend the expression's lifetime to the end of the /// scope, use an underscore-prefixed name instead (i.e. _var). If you want to /// explicitly drop the expression, `std::mem::drop` conveys your intention /// better and is less error-prone. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// Bad: /// ```rust,ignore diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index aa763b5c5e6..3cffb507f70 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -73,14 +73,13 @@ use rustc_session::Session; /// use clippy_lints::declare_clippy_lint; /// /// declare_clippy_lint! { -/// /// **What it does:** Checks for ... (describe what the lint matches). +/// /// ### What it does +/// /// Checks for ... (describe what the lint matches). /// /// -/// /// **Why is this bad?** Supply the reason for linting the code. -/// /// -/// /// **Known problems:** None. (Or describe where it could go wrong.) -/// /// -/// /// **Example:** +/// /// ### Why is this bad? +/// /// Supply the reason for linting the code. /// /// +/// /// ### Example /// /// ```rust /// /// // Bad /// /// Insert a short example of code that triggers the lint diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 5ae68ba5b2f..e5e6f8d25cc 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -18,20 +18,22 @@ use rustc_span::source_map::Span; use rustc_span::symbol::{kw, Symbol}; declare_clippy_lint! { - /// **What it does:** Checks for lifetime annotations which can be removed by + /// ### What it does + /// Checks for lifetime annotations which can be removed by /// relying on lifetime elision. /// - /// **Why is this bad?** The additional lifetimes make the code look more + /// ### Why is this bad? + /// The additional lifetimes make the code look more /// complicated, while there is nothing out of the ordinary going on. Removing /// them leads to more readable code. /// - /// **Known problems:** + /// ### Known problems /// - We bail out if the function has a `where` clause where lifetimes /// are mentioned due to potenial false positives. /// - Lifetime bounds such as `impl Foo + 'a` and `T: 'a` must be elided with the /// placeholder notation `'_` because the fully elided notation leaves the type bound to `'static`. /// - /// **Example:** + /// ### Example /// ```rust /// // Bad: unnecessary lifetime annotations /// fn in_and_out<'a>(x: &'a u8, y: u8) -> &'a u8 { @@ -50,16 +52,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for lifetimes in generics that are never used + /// ### What it does + /// Checks for lifetimes in generics that are never used /// anywhere else. /// - /// **Why is this bad?** The additional lifetimes make the code look more + /// ### Why is this bad? + /// The additional lifetimes make the code look more /// complicated, while there is nothing out of the ordinary going on. Removing /// them leads to more readable code. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad: unnecessary lifetimes /// fn unused_lifetime<'a>(x: u8) { diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index e0c5578bd60..699ddce0cff 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -16,15 +16,14 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use std::iter; declare_clippy_lint! { - /// **What it does:** Warns if a long integral or floating-point constant does + /// ### What it does + /// Warns if a long integral or floating-point constant does /// not contain underscores. /// - /// **Why is this bad?** Reading long numbers is difficult without separators. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Reading long numbers is difficult without separators. /// + /// ### Example /// ```rust /// // Bad /// let x: u64 = 61864918973511; @@ -38,17 +37,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns for mistyped suffix in literals + /// ### What it does + /// Warns for mistyped suffix in literals /// - /// **Why is this bad?** This is most probably a typo + /// ### Why is this bad? + /// This is most probably a typo /// - /// **Known problems:** + /// ### Known problems /// - Recommends a signed suffix, even though the number might be too big and an unsigned /// suffix is required /// - Does not match on `_127` since that is a valid grouping for decimal and octal numbers /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Probably mistyped /// 2_32; @@ -62,16 +62,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns if an integral or floating-point constant is + /// ### What it does + /// Warns if an integral or floating-point constant is /// grouped inconsistently with underscores. /// - /// **Why is this bad?** Readers may incorrectly interpret inconsistently + /// ### Why is this bad? + /// Readers may incorrectly interpret inconsistently /// grouped digits. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let x: u64 = 618_64_9189_73_511; @@ -85,15 +84,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns if hexadecimal or binary literals are not grouped + /// ### What it does + /// Warns if hexadecimal or binary literals are not grouped /// by nibble or byte. /// - /// **Why is this bad?** Negatively impacts readability. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Negatively impacts readability. /// + /// ### Example /// ```rust /// let x: u32 = 0xFFF_FFF; /// let y: u8 = 0b01_011_101; @@ -104,16 +102,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns if the digits of an integral or floating-point + /// ### What it does + /// Warns if the digits of an integral or floating-point /// constant are grouped into groups that /// are too large. /// - /// **Why is this bad?** Negatively impacts readability. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Negatively impacts readability. /// + /// ### Example /// ```rust /// let x: u64 = 6186491_8973511; /// ``` @@ -123,15 +120,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns if there is a better representation for a numeric literal. + /// ### What it does + /// Warns if there is a better representation for a numeric literal. /// - /// **Why is this bad?** Especially for big powers of 2 a hexadecimal representation is more + /// ### Why is this bad? + /// Especially for big powers of 2 a hexadecimal representation is more /// readable than a decimal representation. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// `255` => `0xFF` /// `65_535` => `0xFFFF` /// `4_042_322_160` => `0xF0F0_F0F0` diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 56a123b69c6..7ca54d53972 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -26,14 +26,14 @@ use rustc_span::source_map::Span; use utils::{get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor}; declare_clippy_lint! { - /// **What it does:** Checks for for-loops that manually copy items between + /// ### What it does + /// Checks for for-loops that manually copy items between /// slices that could be optimized by having a memcpy. /// - /// **Why is this bad?** It is not as fast as a memcpy. + /// ### Why is this bad? + /// It is not as fast as a memcpy. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let src = vec![1]; /// # let mut dst = vec![0; 65]; @@ -53,15 +53,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for looping over the range of `0..len` of some + /// ### What it does + /// Checks for looping over the range of `0..len` of some /// collection just to get the values by index. /// - /// **Why is this bad?** Just iterating the collection itself makes the intent + /// ### Why is this bad? + /// Just iterating the collection itself makes the intent /// more clear and is probably faster. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let vec = vec!['a', 'b', 'c']; /// for i in 0..vec.len() { @@ -81,15 +81,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for loops on `x.iter()` where `&x` will do, and + /// ### What it does + /// Checks for loops on `x.iter()` where `&x` will do, and /// suggests the latter. /// - /// **Why is this bad?** Readability. + /// ### Why is this bad? + /// Readability. /// - /// **Known problems:** False negatives. We currently only warn on some known + /// ### Known problems + /// False negatives. We currently only warn on some known /// types. /// - /// **Example:** + /// ### Example /// ```rust /// // with `y` a `Vec` or slice: /// # let y = vec![1]; @@ -110,14 +113,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for loops on `y.into_iter()` where `y` will do, and + /// ### What it does + /// Checks for loops on `y.into_iter()` where `y` will do, and /// suggests the latter. /// - /// **Why is this bad?** Readability. + /// ### Why is this bad? + /// Readability. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// # let y = vec![1]; /// // with `y` a `Vec` or slice: @@ -138,18 +141,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for loops on `x.next()`. + /// ### What it does + /// Checks for loops on `x.next()`. /// - /// **Why is this bad?** `next()` returns either `Some(value)` if there was a + /// ### Why is this bad? + /// `next()` returns either `Some(value)` if there was a /// value, or `None` otherwise. The insidious thing is that `Option<_>` /// implements `IntoIterator`, so that possibly one value will be iterated, /// leading to some hard to find bugs. No one will want to write such code /// [except to win an Underhanded Rust /// Contest](https://www.reddit.com/r/rust/comments/3hb0wm/underhanded_rust_contest/cu5yuhr). /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// for x in y.next() { /// .. @@ -161,14 +164,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `for` loops over `Option` or `Result` values. + /// ### What it does + /// Checks for `for` loops over `Option` or `Result` values. /// - /// **Why is this bad?** Readability. This is more clearly expressed as an `if + /// ### Why is this bad? + /// Readability. This is more clearly expressed as an `if /// let`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let opt = Some(1); /// @@ -204,15 +207,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Detects `loop + match` combinations that are easier + /// ### What it does + /// Detects `loop + match` combinations that are easier /// written as a `while let` loop. /// - /// **Why is this bad?** The `while let` loop is usually shorter and more + /// ### Why is this bad? + /// The `while let` loop is usually shorter and more /// readable. /// - /// **Known problems:** Sometimes the wrong binding is displayed ([#383](https://github.com/rust-lang/rust-clippy/issues/383)). + /// ### Known problems + /// Sometimes the wrong binding is displayed ([#383](https://github.com/rust-lang/rust-clippy/issues/383)). /// - /// **Example:** + /// ### Example /// ```rust,no_run /// # let y = Some(1); /// loop { @@ -233,16 +239,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for functions collecting an iterator when collect + /// ### What it does + /// Checks for functions collecting an iterator when collect /// is not needed. /// - /// **Why is this bad?** `collect` causes the allocation of a new data structure, + /// ### Why is this bad? + /// `collect` causes the allocation of a new data structure, /// when this allocation may not be needed. /// - /// **Known problems:** - /// None - /// - /// **Example:** + /// ### Example /// ```rust /// # let iterator = vec![1].into_iter(); /// let len = iterator.clone().collect::>().len(); @@ -255,15 +260,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks `for` loops over slices with an explicit counter + /// ### What it does + /// Checks `for` loops over slices with an explicit counter /// and suggests the use of `.enumerate()`. /// - /// **Why is it bad?** Using `.enumerate()` makes the intent more clear, + /// ### Why is this bad? + /// Using `.enumerate()` makes the intent more clear, /// declutters the code and may be faster in some instances. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let v = vec![1]; /// # fn bar(bar: usize, baz: usize) {} @@ -285,9 +290,11 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for empty `loop` expressions. + /// ### What it does + /// Checks for empty `loop` expressions. /// - /// **Why is this bad?** These busy loops burn CPU cycles without doing + /// ### Why is this bad? + /// These busy loops burn CPU cycles without doing /// anything. It is _almost always_ a better idea to `panic!` than to have /// a busy loop. /// @@ -306,9 +313,7 @@ declare_clippy_lint! { /// - [`x86_64::instructions::hlt`](https://docs.rs/x86_64/0.12.2/x86_64/instructions/fn.hlt.html) /// - [`cortex_m::asm::wfi`](https://docs.rs/cortex-m/0.6.3/cortex_m/asm/fn.wfi.html) /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```no_run /// loop {} /// ``` @@ -318,14 +323,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `while let` expressions on iterators. + /// ### What it does + /// Checks for `while let` expressions on iterators. /// - /// **Why is this bad?** Readability. A simple `for` loop is shorter and conveys + /// ### Why is this bad? + /// Readability. A simple `for` loop is shorter and conveys /// the intent better. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// while let Some(val) = iter() { /// .. @@ -337,15 +342,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for iterating a map (`HashMap` or `BTreeMap`) and + /// ### What it does + /// Checks for iterating a map (`HashMap` or `BTreeMap`) and /// ignoring either the keys or values. /// - /// **Why is this bad?** Readability. There are `keys` and `values` methods that + /// ### Why is this bad? + /// Readability. There are `keys` and `values` methods that /// can be used to express that don't need the values or keys. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// for (k, _) in &map { /// .. @@ -365,15 +370,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for loops that will always `break`, `return` or + /// ### What it does + /// Checks for loops that will always `break`, `return` or /// `continue` an outer loop. /// - /// **Why is this bad?** This loop never loops, all it does is obfuscating the + /// ### Why is this bad? + /// This loop never loops, all it does is obfuscating the /// code. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// loop { /// ..; @@ -386,13 +391,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for loops which have a range bound that is a mutable variable - /// - /// **Why is this bad?** One might think that modifying the mutable variable changes the loop bounds + /// ### What it does + /// Checks for loops which have a range bound that is a mutable variable /// - /// **Known problems:** None + /// ### Why is this bad? + /// One might think that modifying the mutable variable changes the loop bounds /// - /// **Example:** + /// ### Example /// ```rust /// let mut foo = 42; /// for i in 0..foo { @@ -406,17 +411,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks whether variables used within while loop condition + /// ### What it does + /// Checks whether variables used within while loop condition /// can be (and are) mutated in the body. /// - /// **Why is this bad?** If the condition is unchanged, entering the body of the loop + /// ### Why is this bad? + /// If the condition is unchanged, entering the body of the loop /// will lead to an infinite loop. /// - /// **Known problems:** If the `while`-loop is in a closure, the check for mutation of the + /// ### Known problems + /// If the `while`-loop is in a closure, the check for mutation of the /// condition variables in the body can cause false negatives. For example when only `Upvar` `a` is /// in the condition and only `Upvar` `b` gets mutated in the body, the lint will not trigger. /// - /// **Example:** + /// ### Example /// ```rust /// let i = 0; /// while i > 10 { @@ -429,15 +437,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks whether a for loop is being used to push a constant + /// ### What it does + /// Checks whether a for loop is being used to push a constant /// value into a Vec. /// - /// **Why is this bad?** This kind of operation can be expressed more succinctly with + /// ### Why is this bad? + /// This kind of operation can be expressed more succinctly with /// `vec![item;SIZE]` or `vec.resize(NEW_SIZE, item)` and using these alternatives may also /// have better performance. - /// **Known problems:** None /// - /// **Example:** + /// ### Example /// ```rust /// let item1 = 2; /// let item2 = 3; @@ -462,13 +471,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks whether a for loop has a single element. + /// ### What it does + /// Checks whether a for loop has a single element. /// - /// **Why is this bad?** There is no reason to have a loop of a + /// ### Why is this bad? + /// There is no reason to have a loop of a /// single element. - /// **Known problems:** None /// - /// **Example:** + /// ### Example /// ```rust /// let item1 = 2; /// for item in &[item1] { @@ -487,15 +497,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Check for unnecessary `if let` usage in a for loop + /// ### What it does + /// Check for unnecessary `if let` usage in a for loop /// where only the `Some` or `Ok` variant of the iterator element is used. /// - /// **Why is this bad?** It is verbose and can be simplified + /// ### Why is this bad? + /// It is verbose and can be simplified /// by first calling the `flatten` method on the `Iterator`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// ```rust /// let x = vec![Some(1), Some(2), Some(3)]; diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 66479ae264e..a371f8bbd3c 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -12,14 +12,14 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{edition::Edition, sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for `#[macro_use] use...`. + /// ### What it does + /// Checks for `#[macro_use] use...`. /// - /// **Why is this bad?** Since the Rust 2018 edition you can import + /// ### Why is this bad? + /// Since the Rust 2018 edition you can import /// macro's directly, this is considered idiomatic. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// #[macro_use] /// use some_macro; diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 07d8a440aea..776e4b3fe76 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -7,14 +7,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for recursion using the entrypoint. + /// ### What it does + /// Checks for recursion using the entrypoint. /// - /// **Why is this bad?** Apart from special setups (which we could detect following attributes like #![no_std]), + /// ### Why is this bad? + /// Apart from special setups (which we could detect following attributes like #![no_std]), /// recursing into main() seems like an unintuitive antipattern we should be able to detect. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```no_run /// fn main() { /// main(); diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 5d88ff3b99f..8e1385fb83a 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -14,14 +14,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; declare_clippy_lint! { - /// **What it does:** It checks for manual implementations of `async` functions. + /// ### What it does + /// It checks for manual implementations of `async` functions. /// - /// **Why is this bad?** It's more idiomatic to use the dedicated syntax. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// It's more idiomatic to use the dedicated syntax. /// + /// ### Example /// ```rust /// use std::future::Future; /// diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index 563d5cdb5fb..7dec1595e0d 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -16,14 +16,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, SyntaxContext}; declare_clippy_lint! { - /// **What it does:** Checks for usages of `match` which could be implemented using `map` + /// ### What it does + /// Checks for usages of `match` which could be implemented using `map` /// - /// **Why is this bad?** Using the `map` method is clearer and more concise. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Using the `map` method is clearer and more concise. /// + /// ### Example /// ```rust /// match Some(0) { /// Some(x) => Some(x + 1), diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 54f714b54b6..335ea001ee4 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -11,15 +11,14 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for manual implementations of the non-exhaustive pattern. + /// ### What it does + /// Checks for manual implementations of the non-exhaustive pattern. /// - /// **Why is this bad?** Using the #[non_exhaustive] attribute expresses better the intent + /// ### Why is this bad? + /// Using the #[non_exhaustive] attribute expresses better the intent /// and allows possible optimizations when applied to enums. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct S { /// pub a: i32, diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index 847c8c648b0..b2f287af697 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -13,15 +13,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** + /// ### What it does + /// /// Finds patterns that reimplement `Option::ok_or`. /// - /// **Why is this bad?** - /// Concise code helps focusing on behavior instead of boilerplate. + /// ### Why is this bad? /// - /// **Known problems:** None. + /// Concise code helps focusing on behavior instead of boilerplate. /// - /// **Examples:** + /// ### Examples /// ```rust /// let foo: Option = None; /// foo.map_or(Err("error"), |v| Ok(v)); diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 61b5fe81fa9..db12c377488 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -18,21 +18,17 @@ use rustc_span::source_map::Spanned; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing using /// the pattern's length. /// - /// **Why is this bad?** + /// ### Why is this bad? /// Using `str:strip_{prefix,suffix}` is safer and may have better performance as there is no /// slicing which may panic and the compiler does not need to insert this panic code. It is /// also sometimes more readable as it removes the need for duplicating or storing the pattern /// used by `str::{starts,ends}_with` and in the slicing. /// - /// **Known problems:** - /// None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let s = "hello, world!"; /// if s.starts_with("hello, ") { diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 9d8d77cf8f0..426789742d5 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -15,15 +15,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Finds patterns that reimplement `Option::unwrap_or` or `Result::unwrap_or`. /// - /// **Why is this bad?** + /// ### Why is this bad? /// Concise code helps focusing on behavior instead of boilerplate. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let foo: Option = None; /// match foo { diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index e1f80ab025c..394606200bb 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -15,16 +15,15 @@ use rustc_span::symbol::Ident; use rustc_span::{sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for usage of `map(|x| x.clone())` or + /// ### What it does + /// Checks for usage of `map(|x| x.clone())` or /// dereferencing closures for `Copy` types, on `Iterator` or `Option`, /// and suggests `cloned()` or `copied()` instead /// - /// **Why is this bad?** Readability, this can be written more concisely - /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Why is this bad? + /// Readability, this can be written more concisely /// + /// ### Example /// ```rust /// let x = vec![42, 43]; /// let y = x.iter(); diff --git a/clippy_lints/src/map_err_ignore.rs b/clippy_lints/src/map_err_ignore.rs index 425a9734e5f..82d3732326e 100644 --- a/clippy_lints/src/map_err_ignore.rs +++ b/clippy_lints/src/map_err_ignore.rs @@ -4,13 +4,13 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for instances of `map_err(|_| Some::Enum)` + /// ### What it does + /// Checks for instances of `map_err(|_| Some::Enum)` /// - /// **Why is this bad?** This `map_err` throws away the original error rather than allowing the enum to contain and report the cause of the error + /// ### Why is this bad? + /// This `map_err` throws away the original error rather than allowing the enum to contain and report the cause of the error /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Before: /// ```rust /// use std::fmt; diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 57cd907e77e..fd40590d077 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -12,16 +12,15 @@ use rustc_span::source_map::Span; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for usage of `option.map(f)` where f is a function + /// ### What it does + /// Checks for usage of `option.map(f)` where f is a function /// or closure that returns the unit type `()`. /// - /// **Why is this bad?** Readability, this can be written more clearly with + /// ### Why is this bad? + /// Readability, this can be written more clearly with /// an if let statement /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// # fn do_stuff() -> Option { Some(String::new()) } /// # fn log_err_msg(foo: String) -> Option { Some(foo) } @@ -54,16 +53,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `result.map(f)` where f is a function + /// ### What it does + /// Checks for usage of `result.map(f)` where f is a function /// or closure that returns the unit type `()`. /// - /// **Why is this bad?** Readability, this can be written more clearly with + /// ### Why is this bad? + /// Readability, this can be written more clearly with /// an if let statement /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// # fn do_stuff() -> Result { Ok(String::new()) } /// # fn log_err_msg(foo: String) -> Result { Ok(foo) } diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index ca6fb0831fe..e66a35452f0 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -10,13 +10,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for `match vec[idx]` or `match vec[n..m]`. + /// ### What it does + /// Checks for `match vec[idx]` or `match vec[n..m]`. /// - /// **Why is this bad?** This can panic at runtime. + /// ### Why is this bad? + /// This can panic at runtime. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust, no_run /// let arr = vec![0, 1, 2, 3]; /// let idx = 1; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index d7f600b3ab2..5360c02f905 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -35,14 +35,14 @@ use std::iter; use std::ops::Bound; declare_clippy_lint! { - /// **What it does:** Checks for matches with a single arm where an `if let` + /// ### What it does + /// Checks for matches with a single arm where an `if let` /// will usually suffice. /// - /// **Why is this bad?** Just readability – `if let` nests less than a `match`. + /// ### Why is this bad? + /// Just readability – `if let` nests less than a `match`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # fn bar(stool: &str) {} /// # let x = Some("abc"); @@ -63,15 +63,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for matches with two arms where an `if let else` will + /// ### What it does + /// Checks for matches with two arms where an `if let else` will /// usually suffice. /// - /// **Why is this bad?** Just readability – `if let` nests less than a `match`. - /// - /// **Known problems:** Personal style preferences may differ. + /// ### Why is this bad? + /// Just readability – `if let` nests less than a `match`. /// - /// **Example:** + /// ### Known problems + /// Personal style preferences may differ. /// + /// ### Example /// Using `match`: /// /// ```rust @@ -102,16 +104,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for matches where all arms match a reference, + /// ### What it does + /// Checks for matches where all arms match a reference, /// suggesting to remove the reference and deref the matched expression /// instead. It also checks for `if let &foo = bar` blocks. /// - /// **Why is this bad?** It just makes the code less readable. That reference + /// ### Why is this bad? + /// It just makes the code less readable. That reference /// destructuring adds nothing to the code. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// match x { @@ -133,14 +135,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for matches where match expression is a `bool`. It + /// ### What it does + /// Checks for matches where match expression is a `bool`. It /// suggests to replace the expression with an `if...else` block. /// - /// **Why is this bad?** It makes the code less readable. + /// ### Why is this bad? + /// It makes the code less readable. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # fn foo() {} /// # fn bar() {} @@ -167,14 +169,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for overlapping match arms. + /// ### What it does + /// Checks for overlapping match arms. /// - /// **Why is this bad?** It is likely to be an error and if not, makes the code + /// ### Why is this bad? + /// It is likely to be an error and if not, makes the code /// less obvious. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = 5; /// match x { @@ -189,15 +191,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for arm which matches all errors with `Err(_)` + /// ### What it does + /// Checks for arm which matches all errors with `Err(_)` /// and take drastic actions like `panic!`. /// - /// **Why is this bad?** It is generally a bad practice, similar to + /// ### Why is this bad? + /// It is generally a bad practice, similar to /// catching all exceptions in java with `catch(Exception)` /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x: Result = Ok(3); /// match x { @@ -211,14 +213,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for match which is used to add a reference to an + /// ### What it does + /// Checks for match which is used to add a reference to an /// `Option` value. /// - /// **Why is this bad?** Using `as_ref()` or `as_mut()` instead is shorter. + /// ### Why is this bad? + /// Using `as_ref()` or `as_mut()` instead is shorter. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x: Option<()> = None; /// @@ -237,14 +239,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for wildcard enum matches using `_`. + /// ### What it does + /// Checks for wildcard enum matches using `_`. /// - /// **Why is this bad?** New enum variants added by library updates can be missed. + /// ### Why is this bad? + /// New enum variants added by library updates can be missed. /// - /// **Known problems:** Suggested replacements may be incorrect if guards exhaustively cover some + /// ### Known problems + /// Suggested replacements may be incorrect if guards exhaustively cover some /// variants, and also may not use correct path to enum if it's not present in the current scope. /// - /// **Example:** + /// ### Example /// ```rust /// # enum Foo { A(usize), B(usize) } /// # let x = Foo::B(1); @@ -266,15 +271,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for wildcard enum matches for a single variant. + /// ### What it does + /// Checks for wildcard enum matches for a single variant. /// - /// **Why is this bad?** New enum variants added by library updates can be missed. + /// ### Why is this bad? + /// New enum variants added by library updates can be missed. /// - /// **Known problems:** Suggested replacements may not use correct path to enum + /// ### Known problems + /// Suggested replacements may not use correct path to enum /// if it's not present in the current scope. /// - /// **Example:** - /// + /// ### Example /// ```rust /// # enum Foo { A, B, C } /// # let x = Foo::B; @@ -298,14 +305,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for wildcard pattern used with others patterns in same match arm. + /// ### What it does + /// Checks for wildcard pattern used with others patterns in same match arm. /// - /// **Why is this bad?** Wildcard pattern already covers any other pattern as it will match anyway. + /// ### Why is this bad? + /// Wildcard pattern already covers any other pattern as it will match anyway. /// It makes the code less readable, especially to spot wildcard pattern use in match arm. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// match "foo" { @@ -325,14 +332,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for matches being used to destructure a single-variant enum + /// ### What it does + /// Checks for matches being used to destructure a single-variant enum /// or tuple struct where a `let` will suffice. /// - /// **Why is this bad?** Just readability – `let` doesn't nest, whereas a `match` does. + /// ### Why is this bad? + /// Just readability – `let` doesn't nest, whereas a `match` does. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// enum Wrapper { /// Data(i32), @@ -360,14 +367,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for useless match that binds to only one value. + /// ### What it does + /// Checks for useless match that binds to only one value. /// - /// **Why is this bad?** Readability and needless complexity. + /// ### Why is this bad? + /// Readability and needless complexity. /// - /// **Known problems:** Suggested replacements may be incorrect when `match` + /// ### Known problems + /// Suggested replacements may be incorrect when `match` /// is actually binding temporary value, bringing a 'dropped while borrowed' error. /// - /// **Example:** + /// ### Example /// ```rust /// # let a = 1; /// # let b = 2; @@ -388,14 +398,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for unnecessary '..' pattern binding on struct when all fields are explicitly matched. + /// ### What it does + /// Checks for unnecessary '..' pattern binding on struct when all fields are explicitly matched. /// - /// **Why is this bad?** Correctness and readability. It's like having a wildcard pattern after + /// ### Why is this bad? + /// Correctness and readability. It's like having a wildcard pattern after /// matching all enum variants explicitly. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # struct A { a: i32 } /// let a = A { a: 5 }; @@ -418,21 +428,23 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Lint for redundant pattern matching over `Result`, `Option`, + /// ### What it does + /// Lint for redundant pattern matching over `Result`, `Option`, /// `std::task::Poll` or `std::net::IpAddr` /// - /// **Why is this bad?** It's more concise and clear to just use the proper + /// ### Why is this bad? + /// It's more concise and clear to just use the proper /// utility function /// - /// **Known problems:** This will change the drop order for the matched type. Both `if let` and + /// ### Known problems + /// This will change the drop order for the matched type. Both `if let` and /// `while let` will drop the value at the end of the block, both `if` and `while` will drop the /// value before entering the block. For most types this change will not matter, but for a few /// types this will not be an acceptable change (e.g. locks). See the /// [reference](https://doc.rust-lang.org/reference/destructors.html#drop-scopes) for more about /// drop order. /// - /// **Example:** - /// + /// ### Example /// ```rust /// # use std::task::Poll; /// # use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; @@ -471,15 +483,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `match` or `if let` expressions producing a + /// ### What it does + /// Checks for `match` or `if let` expressions producing a /// `bool` that could be written using `matches!` /// - /// **Why is this bad?** Readability and needless complexity. + /// ### Why is this bad? + /// Readability and needless complexity. /// - /// **Known problems:** This lint falsely triggers, if there are arms with + /// ### Known problems + /// This lint falsely triggers, if there are arms with /// `cfg` attributes that remove an arm evaluating to `false`. /// - /// **Example:** + /// ### Example /// ```rust /// let x = Some(5); /// @@ -504,17 +519,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `match` with identical arm bodies. + /// ### What it does + /// Checks for `match` with identical arm bodies. /// - /// **Why is this bad?** This is probably a copy & paste error. If arm bodies + /// ### Why is this bad? + /// This is probably a copy & paste error. If arm bodies /// are the same on purpose, you can factor them /// [using `|`](https://doc.rust-lang.org/book/patterns.html#multiple-patterns). /// - /// **Known problems:** False positive possible with order dependent `match` + /// ### Known problems + /// False positive possible with order dependent `match` /// (see issue /// [#860](https://github.com/rust-lang/rust-clippy/issues/860)). /// - /// **Example:** + /// ### Example /// ```rust,ignore /// match foo { /// Bar => bar(), diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index aca96e06ef2..59176c4b846 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -9,14 +9,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for calls of `mem::discriminant()` on a non-enum type. + /// ### What it does + /// Checks for calls of `mem::discriminant()` on a non-enum type. /// - /// **Why is this bad?** The value of `mem::discriminant()` on non-enum types + /// ### Why is this bad? + /// The value of `mem::discriminant()` on non-enum types /// is unspecified. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// use std::mem; /// diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index a28cb5f32fe..07202a59c4b 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -5,15 +5,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for usage of `std::mem::forget(t)` where `t` is + /// ### What it does + /// Checks for usage of `std::mem::forget(t)` where `t` is /// `Drop`. /// - /// **Why is this bad?** `std::mem::forget(t)` prevents `t` from running its + /// ### Why is this bad? + /// `std::mem::forget(t)` prevents `t` from running its /// destructor, possibly causing leaks. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use std::mem; /// # use std::rc::Rc; diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 183daee3617..3d071c9081b 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -14,16 +14,16 @@ use rustc_span::source_map::Span; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** Checks for `mem::replace()` on an `Option` with + /// ### What it does + /// Checks for `mem::replace()` on an `Option` with /// `None`. /// - /// **Why is this bad?** `Option` already has the method `take()` for + /// ### Why is this bad? + /// `Option` already has the method `take()` for /// taking its current value (Some(..) or None) and replacing it with /// `None`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// use std::mem; /// @@ -41,17 +41,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `mem::replace(&mut _, mem::uninitialized())` + /// ### What it does + /// Checks for `mem::replace(&mut _, mem::uninitialized())` /// and `mem::replace(&mut _, mem::zeroed())`. /// - /// **Why is this bad?** This will lead to undefined behavior even if the + /// ### Why is this bad? + /// This will lead to undefined behavior even if the /// value is overwritten later, because the uninitialized value may be /// observed in the case of a panic. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ``` /// use std::mem; ///# fn may_panic(v: Vec) -> Vec { v } @@ -73,15 +72,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `std::mem::replace` on a value of type + /// ### What it does + /// Checks for `std::mem::replace` on a value of type /// `T` with `T::default()`. /// - /// **Why is this bad?** `std::mem` module already has the method `take` to + /// ### Why is this bad? + /// `std::mem` module already has the method `take` to /// take the current value and replace it with the default value of that type. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let mut text = String::from("foo"); /// let replaced = std::mem::replace(&mut text, String::default()); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 283fcf281df..d3e12023814 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -80,16 +80,15 @@ use rustc_span::{sym, Span}; use rustc_typeck::hir_ty_to_ty; declare_clippy_lint! { - /// **What it does:** Checks for usages of `cloned()` on an `Iterator` or `Option` where + /// ### What it does + /// Checks for usages of `cloned()` on an `Iterator` or `Option` where /// `copied()` could be used instead. /// - /// **Why is this bad?** `copied()` is better because it guarantees that the type being cloned + /// ### Why is this bad? + /// `copied()` is better because it guarantees that the type being cloned /// implements `Copy`. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// [1, 2, 3].iter().cloned(); /// ``` @@ -103,16 +102,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usages of `Iterator::flat_map()` where `filter_map()` could be + /// ### What it does + /// Checks for usages of `Iterator::flat_map()` where `filter_map()` could be /// used instead. /// - /// **Why is this bad?** When applicable, `filter_map()` is more clear since it shows that + /// ### Why is this bad? + /// When applicable, `filter_map()` is more clear since it shows that /// `Option` is used to produce 0 or 1 items. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let nums: Vec = ["1", "2", "whee!"].iter().flat_map(|x| x.parse().ok()).collect(); /// ``` @@ -126,9 +124,11 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `.unwrap()` calls on `Option`s and on `Result`s. + /// ### What it does + /// Checks for `.unwrap()` calls on `Option`s and on `Result`s. /// - /// **Why is this bad?** It is better to handle the `None` or `Err` case, + /// ### Why is this bad? + /// It is better to handle the `None` or `Err` case, /// or at least call `.expect(_)` with a more helpful message. Still, for a lot of /// quick-and-dirty code, `unwrap` is a good choice, which is why this lint is /// `Allow` by default. @@ -141,9 +141,7 @@ declare_clippy_lint! { /// messages on display. Therefore, it may be beneficial to look at the places /// where they may get displayed. Activate this lint to do just that. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ```rust /// # let opt = Some(1); /// @@ -171,9 +169,11 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `.expect()` calls on `Option`s and `Result`s. + /// ### What it does + /// Checks for `.expect()` calls on `Option`s and `Result`s. /// - /// **Why is this bad?** Usually it is better to handle the `None` or `Err` case. + /// ### Why is this bad? + /// Usually it is better to handle the `None` or `Err` case. /// Still, for a lot of quick-and-dirty code, `expect` is a good choice, which is why /// this lint is `Allow` by default. /// @@ -181,9 +181,7 @@ declare_clippy_lint! { /// values. Normally, you want to implement more sophisticated error handling, /// and propagate errors upwards with `?` operator. /// - /// **Known problems:** None. - /// - /// **Examples:** + /// ### Examples /// ```rust,ignore /// # let opt = Some(1); /// @@ -213,20 +211,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for methods that should live in a trait + /// ### What it does + /// Checks for methods that should live in a trait /// implementation of a `std` trait (see [llogiq's blog /// post](http://llogiq.github.io/2015/07/30/traits.html) for further /// information) instead of an inherent implementation. /// - /// **Why is this bad?** Implementing the traits improve ergonomics for users of + /// ### Why is this bad? + /// Implementing the traits improve ergonomics for users of /// the code, often with very little cost. Also people seeing a `mul(...)` /// method /// may expect `*` to work equally, so you should have good reason to disappoint /// them. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// struct X; /// impl X { @@ -242,7 +240,8 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for methods with certain name prefixes and which + /// ### What it does + /// Checks for methods with certain name prefixes and which /// doesn't match how self is taken. The actual rules are: /// /// |Prefix |Postfix |`self` taken | `self` type | @@ -265,13 +264,12 @@ declare_clippy_lint! { /// Please find more info here: /// https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv /// - /// **Why is this bad?** Consistency breeds readability. If you follow the + /// ### Why is this bad? + /// Consistency breeds readability. If you follow the /// conventions, your users won't be surprised that they, e.g., need to supply a /// mutable reference to a `as_..` function. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # struct X; /// impl X { @@ -287,14 +285,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `ok().expect(..)`. + /// ### What it does + /// Checks for usage of `ok().expect(..)`. /// - /// **Why is this bad?** Because you usually call `expect()` on the `Result` + /// ### Why is this bad? + /// Because you usually call `expect()` on the `Result` /// directly to get a better error message. /// - /// **Known problems:** The error type needs to implement `Debug` + /// ### Known problems + /// The error type needs to implement `Debug` /// - /// **Example:** + /// ### Example /// ```rust /// # let x = Ok::<_, ()>(()); /// @@ -310,15 +311,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `option.map(_).unwrap_or(_)` or `option.map(_).unwrap_or_else(_)` or + /// ### What it does + /// Checks for usage of `option.map(_).unwrap_or(_)` or `option.map(_).unwrap_or_else(_)` or /// `result.map(_).unwrap_or_else(_)`. /// - /// **Why is this bad?** Readability, these can be written more concisely (resp.) as + /// ### Why is this bad? + /// Readability, these can be written more concisely (resp.) as /// `option.map_or(_, _)`, `option.map_or_else(_, _)` and `result.map_or_else(_, _)`. /// - /// **Known problems:** The order of the arguments is not in execution order + /// ### Known problems + /// The order of the arguments is not in execution order /// - /// **Examples:** + /// ### Examples /// ```rust /// # let x = Some(1); /// @@ -347,14 +351,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map_or(None, _)`. + /// ### What it does + /// Checks for usage of `_.map_or(None, _)`. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.and_then(_)`. /// - /// **Known problems:** The order of the arguments is not in execution order. + /// ### Known problems + /// The order of the arguments is not in execution order. /// - /// **Example:** + /// ### Example /// ```rust /// # let opt = Some(1); /// @@ -370,15 +377,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map_or(None, Some)`. + /// ### What it does + /// Checks for usage of `_.map_or(None, Some)`. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.ok()`. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// Bad: /// ```rust /// # let r: Result = Ok(1); @@ -396,16 +402,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.and_then(|x| Some(y))`, `_.and_then(|x| Ok(y))` or + /// ### What it does + /// Checks for usage of `_.and_then(|x| Some(y))`, `_.and_then(|x| Ok(y))` or /// `_.or_else(|x| Err(y))`. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.map(|x| y)` or `_.map_err(|x| y)`. /// - /// **Known problems:** None - /// - /// **Example:** - /// + /// ### Example /// ```rust /// # fn opt() -> Option<&'static str> { Some("42") } /// # fn res() -> Result<&'static str, &'static str> { Ok("42") } @@ -429,14 +434,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.filter(_).next()`. + /// ### What it does + /// Checks for usage of `_.filter(_).next()`. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.find(_)`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let vec = vec![1]; /// vec.iter().filter(|x| **x == 0).next(); @@ -452,14 +457,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.skip_while(condition).next()`. + /// ### What it does + /// Checks for usage of `_.skip_while(condition).next()`. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.find(!condition)`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let vec = vec![1]; /// vec.iter().skip_while(|x| **x == 0).next(); @@ -475,14 +480,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map(_).flatten(_)` on `Iterator` and `Option` + /// ### What it does + /// Checks for usage of `_.map(_).flatten(_)` on `Iterator` and `Option` /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.flat_map(_)` /// - /// **Known problems:** - /// - /// **Example:** + /// ### Example /// ```rust /// let vec = vec![vec![1]]; /// @@ -498,15 +503,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.filter(_).map(_)` that can be written more simply + /// ### What it does + /// Checks for usage of `_.filter(_).map(_)` that can be written more simply /// as `filter_map(_)`. /// - /// **Why is this bad?** Redundant code in the `filter` and `map` operations is poor style and + /// ### Why is this bad? + /// Redundant code in the `filter` and `map` operations is poor style and /// less performant. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust /// (0_i32..10) @@ -524,15 +529,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.find(_).map(_)` that can be written more simply + /// ### What it does + /// Checks for usage of `_.find(_).map(_)` that can be written more simply /// as `find_map(_)`. /// - /// **Why is this bad?** Redundant code in the `find` and `map` operations is poor style and + /// ### Why is this bad? + /// Redundant code in the `find` and `map` operations is poor style and /// less performant. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust /// (0_i32..10) @@ -550,14 +555,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.filter_map(_).next()`. + /// ### What it does + /// Checks for usage of `_.filter_map(_).next()`. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.find_map(_)`. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// (0..3).filter_map(|x| if x == 2 { Some(x) } else { None }).next(); /// ``` @@ -572,13 +577,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `flat_map(|x| x)`. + /// ### What it does + /// Checks for usage of `flat_map(|x| x)`. /// - /// **Why is this bad?** Readability, this can be written more concisely by using `flatten`. + /// ### Why is this bad? + /// Readability, this can be written more concisely by using `flatten`. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// # let iter = vec![vec![0]].into_iter(); /// iter.flat_map(|x| x); @@ -594,16 +599,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for an iterator or string search (such as `find()`, + /// ### What it does + /// Checks for an iterator or string search (such as `find()`, /// `position()`, or `rposition()`) followed by a call to `is_some()` or `is_none()`. /// - /// **Why is this bad?** Readability, this can be written more concisely as: + /// ### Why is this bad? + /// Readability, this can be written more concisely as: /// * `_.any(_)`, or `_.contains(_)` for `is_some()`, /// * `!_.any(_)`, or `!_.contains(_)` for `is_none()`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let vec = vec![1]; /// vec.iter().find(|x| **x == 0).is_some(); @@ -623,15 +628,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `.chars().next()` on a `str` to check + /// ### What it does + /// Checks for usage of `.chars().next()` on a `str` to check /// if it starts with a given char. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.starts_with(_)`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let name = "foo"; /// if name.chars().next() == Some('_') {}; @@ -647,17 +652,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`, + /// ### What it does + /// Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`, /// etc., and suggests to use `or_else`, `unwrap_or_else`, etc., or /// `unwrap_or_default` instead. /// - /// **Why is this bad?** The function will always be called and potentially + /// ### Why is this bad? + /// The function will always be called and potentially /// allocate an object acting as the default. /// - /// **Known problems:** If the function has side-effects, not calling it will + /// ### Known problems + /// If the function has side-effects, not calling it will /// change the semantic of the program, but you shouldn't rely on that anyway. /// - /// **Example:** + /// ### Example /// ```rust /// # let foo = Some(String::new()); /// foo.unwrap_or(String::new()); @@ -678,15 +686,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `.expect(&format!(...))`, `.expect(foo(..))`, + /// ### What it does + /// Checks for calls to `.expect(&format!(...))`, `.expect(foo(..))`, /// etc., and suggests to use `unwrap_or_else` instead /// - /// **Why is this bad?** The function will always be called. + /// ### Why is this bad? + /// The function will always be called. /// - /// **Known problems:** If the function has side-effects, not calling it will + /// ### Known problems + /// If the function has side-effects, not calling it will /// change the semantics of the program, but you shouldn't rely on that anyway. /// - /// **Example:** + /// ### Example /// ```rust /// # let foo = Some(String::new()); /// # let err_code = "418"; @@ -713,14 +724,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `.clone()` on a `Copy` type. + /// ### What it does + /// Checks for usage of `.clone()` on a `Copy` type. /// - /// **Why is this bad?** The only reason `Copy` types implement `Clone` is for + /// ### Why is this bad? + /// The only reason `Copy` types implement `Clone` is for /// generics, not for using the `clone` method on a concrete type. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// 42u64.clone(); /// ``` @@ -730,15 +741,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `.clone()` on a ref-counted pointer, + /// ### What it does + /// Checks for usage of `.clone()` on a ref-counted pointer, /// (`Rc`, `Arc`, `rc::Weak`, or `sync::Weak`), and suggests calling Clone via unified /// function syntax instead (e.g., `Rc::clone(foo)`). /// - /// **Why is this bad?** Calling '.clone()' on an Rc, Arc, or Weak + /// ### Why is this bad? + /// Calling '.clone()' on an Rc, Arc, or Weak /// can obscure the fact that only the pointer is being cloned, not the underlying /// data. /// - /// **Example:** + /// ### Example /// ```rust /// # use std::rc::Rc; /// let x = Rc::new(1); @@ -755,14 +768,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `.clone()` on an `&&T`. + /// ### What it does + /// Checks for usage of `.clone()` on an `&&T`. /// - /// **Why is this bad?** Cloning an `&&T` copies the inner `&T`, instead of + /// ### Why is this bad? + /// Cloning an `&&T` copies the inner `&T`, instead of /// cloning the underlying `T`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn main() { /// let x = vec![1]; @@ -777,16 +790,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `.to_string()` on an `&&T` where + /// ### What it does + /// Checks for usage of `.to_string()` on an `&&T` where /// `T` implements `ToString` directly (like `&&str` or `&&String`). /// - /// **Why is this bad?** This bypasses the specialized implementation of + /// ### Why is this bad? + /// This bypasses the specialized implementation of /// `ToString` and instead goes through the more expensive string formatting /// facilities. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Generic implementation for `T: Display` is used (slow) /// ["foo", "bar"].iter().map(|s| s.to_string()); @@ -800,14 +813,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `new` not returning a type that contains `Self`. + /// ### What it does + /// Checks for `new` not returning a type that contains `Self`. /// - /// **Why is this bad?** As a convention, `new` methods are used to make a new + /// ### Why is this bad? + /// As a convention, `new` methods are used to make a new /// instance of a type. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// In an impl block: /// ```rust /// # struct Foo; @@ -861,15 +874,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for string methods that receive a single-character + /// ### What it does + /// Checks for string methods that receive a single-character /// `str` as an argument, e.g., `_.split("x")`. /// - /// **Why is this bad?** Performing these methods using a `char` is faster than + /// ### Why is this bad? + /// Performing these methods using a `char` is faster than /// using a `str`. /// - /// **Known problems:** Does not catch multi-byte unicode characters. + /// ### Known problems + /// Does not catch multi-byte unicode characters. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// _.split("x"); @@ -882,14 +898,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calling `.step_by(0)` on iterators which panics. + /// ### What it does + /// Checks for calling `.step_by(0)` on iterators which panics. /// - /// **Why is this bad?** This very much looks like an oversight. Use `panic!()` instead if you + /// ### Why is this bad? + /// This very much looks like an oversight. Use `panic!()` instead if you /// actually intend to panic. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,should_panic /// for x in (0..100).step_by(0) { /// //.. @@ -901,15 +917,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for indirect collection of populated `Option` + /// ### What it does + /// Checks for indirect collection of populated `Option` /// - /// **Why is this bad?** `Option` is like a collection of 0-1 things, so `flatten` + /// ### Why is this bad? + /// `Option` is like a collection of 0-1 things, so `flatten` /// automatically does this without suspicious-looking `unwrap` calls. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let _ = std::iter::empty::>().filter(Option::is_some).map(Option::unwrap); /// ``` @@ -923,16 +938,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the use of `iter.nth(0)`. + /// ### What it does + /// Checks for the use of `iter.nth(0)`. /// - /// **Why is this bad?** `iter.next()` is equivalent to + /// ### Why is this bad? + /// `iter.next()` is equivalent to /// `iter.nth(0)`, as they both consume the next element, /// but is more readable. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// # use std::collections::HashSet; /// // Bad @@ -951,15 +965,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of `.iter().nth()` (and the related + /// ### What it does + /// Checks for use of `.iter().nth()` (and the related /// `.iter_mut().nth()`) on standard library types with O(1) element access. /// - /// **Why is this bad?** `.get()` and `.get_mut()` are more efficient and more + /// ### Why is this bad? + /// `.get()` and `.get_mut()` are more efficient and more /// readable. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let some_vec = vec![0, 1, 2, 3]; /// let bad_vec = some_vec.iter().nth(3); @@ -977,13 +991,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of `.skip(x).next()` on iterators. - /// - /// **Why is this bad?** `.nth(x)` is cleaner + /// ### What it does + /// Checks for use of `.skip(x).next()` on iterators. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// `.nth(x)` is cleaner /// - /// **Example:** + /// ### Example /// ```rust /// let some_vec = vec![0, 1, 2, 3]; /// let bad_vec = some_vec.iter().skip(3).next(); @@ -1001,13 +1015,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of `.get().unwrap()` (or + /// ### What it does + /// Checks for use of `.get().unwrap()` (or /// `.get_mut().unwrap`) on a standard library type which implements `Index` /// - /// **Why is this bad?** Using the Index trait (`[]`) is more clear and more + /// ### Why is this bad? + /// Using the Index trait (`[]`) is more clear and more /// concise. /// - /// **Known problems:** Not a replacement for error handling: Using either + /// ### Known problems + /// Not a replacement for error handling: Using either /// `.unwrap()` or the Index trait (`[]`) carries the risk of causing a `panic` /// if the value being accessed is `None`. If the use of `.get().unwrap()` is a /// temporary placeholder for dealing with the `Option` type, then this does @@ -1016,7 +1033,7 @@ declare_clippy_lint! { /// is handled in a future refactor instead of using `.unwrap()` or the Index /// trait. /// - /// **Example:** + /// ### Example /// ```rust /// let mut some_vec = vec![0, 1, 2, 3]; /// let last = some_vec.get(3).unwrap(); @@ -1034,14 +1051,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for occurrences where one vector gets extended instead of append + /// ### What it does + /// Checks for occurrences where one vector gets extended instead of append /// - /// **Why is this bad?** Using `append` instead of `extend` is more concise and faster - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Using `append` instead of `extend` is more concise and faster /// + /// ### Example /// ```rust /// let mut a = vec![1, 2, 3]; /// let mut b = vec![4, 5, 6]; @@ -1058,14 +1074,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the use of `.extend(s.chars())` where s is a + /// ### What it does + /// Checks for the use of `.extend(s.chars())` where s is a /// `&str` or `String`. /// - /// **Why is this bad?** `.push_str(s)` is clearer + /// ### Why is this bad? + /// `.push_str(s)` is clearer /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let abc = "abc"; /// let def = String::from("def"); @@ -1087,14 +1103,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the use of `.cloned().collect()` on slice to + /// ### What it does + /// Checks for the use of `.cloned().collect()` on slice to /// create a `Vec`. /// - /// **Why is this bad?** `.to_vec()` is clearer - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// `.to_vec()` is clearer /// - /// **Example:** + /// ### Example /// ```rust /// let s = [1, 2, 3, 4, 5]; /// let s2: Vec = s[..].iter().cloned().collect(); @@ -1110,15 +1126,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.chars().last()` or + /// ### What it does + /// Checks for usage of `_.chars().last()` or /// `_.chars().next_back()` on a `str` to check if it ends with a given char. /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.ends_with(_)`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let name = "_"; /// @@ -1134,14 +1150,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `.as_ref()` or `.as_mut()` where the + /// ### What it does + /// Checks for usage of `.as_ref()` or `.as_mut()` where the /// types before and after the call are the same. /// - /// **Why is this bad?** The call is unnecessary. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// The call is unnecessary. /// - /// **Example:** + /// ### Example /// ```rust /// # fn do_stuff(x: &[i32]) {} /// let x: &[i32] = &[1, 2, 3, 4, 5]; @@ -1159,15 +1175,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for using `fold` when a more succinct alternative exists. + /// ### What it does + /// Checks for using `fold` when a more succinct alternative exists. /// Specifically, this checks for `fold`s which could be replaced by `any`, `all`, /// `sum` or `product`. /// - /// **Why is this bad?** Readability. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// Readability. /// - /// **Example:** + /// ### Example /// ```rust /// let _ = (0..3).fold(false, |acc, x| acc || x > 2); /// ``` @@ -1181,16 +1197,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `filter_map` calls which could be replaced by `filter` or `map`. + /// ### What it does + /// Checks for `filter_map` calls which could be replaced by `filter` or `map`. /// More specifically it checks if the closure provided is only performing one of the /// filter or map operations and suggests the appropriate option. /// - /// **Why is this bad?** Complexity. The intent is also clearer if only a single + /// ### Why is this bad? + /// Complexity. The intent is also clearer if only a single /// operation is being performed. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// let _ = (0..3).filter_map(|x| if x > 2 { Some(x) } else { None }); /// @@ -1210,17 +1226,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `into_iter` calls on references which should be replaced by `iter` + /// ### What it does + /// Checks for `into_iter` calls on references which should be replaced by `iter` /// or `iter_mut`. /// - /// **Why is this bad?** Readability. Calling `into_iter` on a reference will not move out its + /// ### Why is this bad? + /// Readability. Calling `into_iter` on a reference will not move out its /// content into the resulting iterator, which is confusing. It is better just call `iter` or /// `iter_mut` directly. /// - /// **Known problems:** None - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let _ = (&vec![3, 4, 5]).into_iter(); @@ -1234,16 +1249,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `map` followed by a `count`. + /// ### What it does + /// Checks for calls to `map` followed by a `count`. /// - /// **Why is this bad?** It looks suspicious. Maybe `map` was confused with `filter`. + /// ### Why is this bad? + /// It looks suspicious. Maybe `map` was confused with `filter`. /// If the `map` call is intentional, this should be rewritten. Or, if you intend to /// drive the iterator to completion, you can just use `for_each` instead. /// - /// **Known problems:** None - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let _ = (0..3).map(|x| x + 2).count(); /// ``` @@ -1253,16 +1267,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `MaybeUninit::uninit().assume_init()`. + /// ### What it does + /// Checks for `MaybeUninit::uninit().assume_init()`. /// - /// **Why is this bad?** For most types, this is undefined behavior. + /// ### Why is this bad? + /// For most types, this is undefined behavior. /// - /// **Known problems:** For now, we accept empty tuples and tuples / arrays + /// ### Known problems + /// For now, we accept empty tuples and tuples / arrays /// of `MaybeUninit`. There may be other types that allow uninitialized /// data, but those are not yet rigorously defined. /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Beware the UB /// use std::mem::MaybeUninit; @@ -1285,12 +1301,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `.checked_add/sub(x).unwrap_or(MAX/MIN)`. + /// ### What it does + /// Checks for `.checked_add/sub(x).unwrap_or(MAX/MIN)`. /// - /// **Why is this bad?** These can be written simply with `saturating_add/sub` methods. - /// - /// **Example:** + /// ### Why is this bad? + /// These can be written simply with `saturating_add/sub` methods. /// + /// ### Example /// ```rust /// # let y: u32 = 0; /// # let x: u32 = 100; @@ -1312,14 +1329,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `offset(_)`, `wrapping_`{`add`, `sub`}, etc. on raw pointers to + /// ### What it does + /// Checks for `offset(_)`, `wrapping_`{`add`, `sub`}, etc. on raw pointers to /// zero-sized types /// - /// **Why is this bad?** This is a no-op, and likely unintended - /// - /// **Known problems:** None + /// ### Why is this bad? + /// This is a no-op, and likely unintended /// - /// **Example:** + /// ### Example /// ```rust /// unsafe { (&() as *const ()).offset(1) }; /// ``` @@ -1329,15 +1346,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `FileType::is_file()`. + /// ### What it does + /// Checks for `FileType::is_file()`. /// - /// **Why is this bad?** When people testing a file type with `FileType::is_file` + /// ### Why is this bad? + /// When people testing a file type with `FileType::is_file` /// they are testing whether a path is something they can get bytes from. But /// `is_file` doesn't cover special file types in unix-like systems, and doesn't cover /// symlink in windows. Using `!FileType::is_dir()` is a better way to that intention. /// - /// **Example:** - /// + /// ### Example /// ```rust /// # || { /// let metadata = std::fs::metadata("foo.txt")?; @@ -1369,14 +1387,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.as_ref().map(Deref::deref)` or it's aliases (such as String::as_str). + /// ### What it does + /// Checks for usage of `_.as_ref().map(Deref::deref)` or it's aliases (such as String::as_str). /// - /// **Why is this bad?** Readability, this can be written more concisely as + /// ### Why is this bad? + /// Readability, this can be written more concisely as /// `_.as_deref()`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let opt = Some("".to_string()); /// opt.as_ref().map(String::as_str) @@ -1394,13 +1412,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `iter().next()` on a Slice or an Array - /// - /// **Why is this bad?** These can be shortened into `.get()` + /// ### What it does + /// Checks for usage of `iter().next()` on a Slice or an Array /// - /// **Known problems:** None. + /// ### Why is this bad? + /// These can be shortened into `.get()` /// - /// **Example:** + /// ### Example /// ```rust /// # let a = [1, 2, 3]; /// # let b = vec![1, 2, 3]; @@ -1420,14 +1438,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns when using `push_str`/`insert_str` with a single-character string literal + /// ### What it does + /// Warns when using `push_str`/`insert_str` with a single-character string literal /// where `push`/`insert` with a `char` would work fine. /// - /// **Why is this bad?** It's less clear that we are pushing a single character. + /// ### Why is this bad? + /// It's less clear that we are pushing a single character. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// let mut string = String::new(); /// string.insert_str(0, "R"); @@ -1445,7 +1463,8 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** As the counterpart to `or_fun_call`, this lint looks for unnecessary + /// ### What it does + /// As the counterpart to `or_fun_call`, this lint looks for unnecessary /// lazily evaluated closures on `Option` and `Result`. /// /// This lint suggests changing the following functions, when eager evaluation results in @@ -1456,13 +1475,14 @@ declare_clippy_lint! { /// - `get_or_insert_with` to `get_or_insert` /// - `ok_or_else` to `ok_or` /// - /// **Why is this bad?** Using eager evaluation is shorter and simpler in some cases. + /// ### Why is this bad? + /// Using eager evaluation is shorter and simpler in some cases. /// - /// **Known problems:** It is possible, but not recommended for `Deref` and `Index` to have + /// ### Known problems + /// It is possible, but not recommended for `Deref` and `Index` to have /// side effects. Eagerly evaluating them can change the semantics of the program. /// - /// **Example:** - /// + /// ### Example /// ```rust /// // example code where clippy issues a warning /// let opt: Option = None; @@ -1481,14 +1501,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map(_).collect::()`. - /// - /// **Why is this bad?** Using `try_for_each` instead is more readable and idiomatic. - /// - /// **Known problems:** None + /// ### What it does + /// Checks for usage of `_.map(_).collect::()`. /// - /// **Example:** + /// ### Why is this bad? + /// Using `try_for_each` instead is more readable and idiomatic. /// + /// ### Example /// ```rust /// (0..3).map(|t| Err(t)).collect::>(); /// ``` @@ -1502,16 +1521,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `from_iter()` function calls on types that implement the `FromIterator` + /// ### What it does + /// Checks for `from_iter()` function calls on types that implement the `FromIterator` /// trait. /// - /// **Why is this bad?** It is recommended style to use collect. See + /// ### Why is this bad? + /// It is recommended style to use collect. See /// [FromIterator documentation](https://doc.rust-lang.org/std/iter/trait.FromIterator.html) /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// use std::iter::FromIterator; /// @@ -1535,15 +1553,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `inspect().for_each()`. + /// ### What it does + /// Checks for usage of `inspect().for_each()`. /// - /// **Why is this bad?** It is the same as performing the computation + /// ### Why is this bad? + /// It is the same as performing the computation /// inside `inspect` at the beginning of the closure in `for_each`. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// [1,2,3,4,5].iter() /// .inspect(|&x| println!("inspect the number: {}", x)) @@ -1565,14 +1582,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `filter_map(|x| x)`. - /// - /// **Why is this bad?** Readability, this can be written more concisely by using `flatten`. + /// ### What it does + /// Checks for usage of `filter_map(|x| x)`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Readability, this can be written more concisely by using `flatten`. /// + /// ### Example /// ```rust /// # let iter = vec![Some(1)].into_iter(); /// iter.filter_map(|x| x); @@ -1588,14 +1604,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for instances of `map(f)` where `f` is the identity function. - /// - /// **Why is this bad?** It can be written more concisely without the call to `map`. + /// ### What it does + /// Checks for instances of `map(f)` where `f` is the identity function. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// It can be written more concisely without the call to `map`. /// + /// ### Example /// ```rust /// let x = [1, 2, 3]; /// let y: Vec<_> = x.iter().map(|x| x).map(|x| 2*x).collect(); @@ -1611,15 +1626,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the use of `.bytes().nth()`. + /// ### What it does + /// Checks for the use of `.bytes().nth()`. /// - /// **Why is this bad?** `.as_bytes().get()` is more efficient and more + /// ### Why is this bad? + /// `.as_bytes().get()` is more efficient and more /// readable. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let _ = "Hello".bytes().nth(3); @@ -1633,15 +1647,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the usage of `_.to_owned()`, `vec.to_vec()`, or similar when calling `_.clone()` would be clearer. + /// ### What it does + /// Checks for the usage of `_.to_owned()`, `vec.to_vec()`, or similar when calling `_.clone()` would be clearer. /// - /// **Why is this bad?** These methods do the same thing as `_.clone()` but may be confusing as + /// ### Why is this bad? + /// These methods do the same thing as `_.clone()` but may be confusing as /// to why we are calling `to_vec` on something that is already a `Vec` or calling `to_owned` on something that is already owned. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let a = vec![1, 2, 3]; /// let b = a.to_vec(); @@ -1659,15 +1672,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the use of `.iter().count()`. + /// ### What it does + /// Checks for the use of `.iter().count()`. /// - /// **Why is this bad?** `.len()` is more efficient and more + /// ### Why is this bad? + /// `.len()` is more efficient and more /// readable. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let some_vec = vec![0, 1, 2, 3]; @@ -1685,17 +1697,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to [`splitn`] + /// ### What it does + /// Checks for calls to [`splitn`] /// (https://doc.rust-lang.org/std/primitive.str.html#method.splitn) and /// related functions with either zero or one splits. /// - /// **Why is this bad?** These calls don't actually split the value and are + /// ### Why is this bad? + /// These calls don't actually split the value and are /// likely to be intended as a different number. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let s = ""; @@ -1715,14 +1726,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for manual implementations of `str::repeat` - /// - /// **Why is this bad?** These are both harder to read, as well as less performant. - /// - /// **Known problems:** None. + /// ### What it does + /// Checks for manual implementations of `str::repeat` /// - /// **Example:** + /// ### Why is this bad? + /// These are both harder to read, as well as less performant. /// + /// ### Example /// ```rust /// // Bad /// let x: String = std::iter::repeat('x').take(10).collect(); diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index ff3473b744e..dc2dd45e4ed 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -8,15 +8,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::cmp::Ordering; declare_clippy_lint! { - /// **What it does:** Checks for expressions where `std::cmp::min` and `max` are + /// ### What it does + /// Checks for expressions where `std::cmp::min` and `max` are /// used to clamp values, but switched so that the result is constant. /// - /// **Why is this bad?** This is in all probability not the intended outcome. At + /// ### Why is this bad? + /// This is in all probability not the intended outcome. At /// the least it hurts readability of the code. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```ignore /// min(0, max(100, x)) /// ``` diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 7cfce2e61cc..c796abe9815 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -25,10 +25,12 @@ use clippy_utils::{ }; declare_clippy_lint! { - /// **What it does:** Checks for function arguments and let bindings denoted as + /// ### What it does + /// Checks for function arguments and let bindings denoted as /// `ref`. /// - /// **Why is this bad?** The `ref` declaration makes the function take an owned + /// ### Why is this bad? + /// The `ref` declaration makes the function take an owned /// value, but turns the argument into a reference (which means that the value /// is destroyed when exiting the function). This adds not much value: either /// take a reference type, or take an owned value and create references in the @@ -37,11 +39,12 @@ declare_clippy_lint! { /// For let bindings, `let x = &foo;` is preferred over `let ref x = foo`. The /// type of `x` is more obvious with the former. /// - /// **Known problems:** If the argument is dereferenced within the function, + /// ### Known problems + /// If the argument is dereferenced within the function, /// removing the `ref` will lead to errors. This can be fixed by removing the /// dereferences, e.g., changing `*x` to `x` within the function. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// fn foo(ref x: u8) -> bool { @@ -59,14 +62,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for comparisons to NaN. + /// ### What it does + /// Checks for comparisons to NaN. /// - /// **Why is this bad?** NaN does not compare meaningfully to anything – not + /// ### Why is this bad? + /// NaN does not compare meaningfully to anything – not /// even itself – so those comparisons are simply wrong. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1.0; /// @@ -82,18 +85,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for (in-)equality comparisons on floating-point + /// ### What it does + /// Checks for (in-)equality comparisons on floating-point /// values (apart from zero), except in functions called `*eq*` (which probably /// implement equality for a type involving floats). /// - /// **Why is this bad?** Floating point calculations are usually imprecise, so + /// ### Why is this bad? + /// Floating point calculations are usually imprecise, so /// asking if two values are *exactly* equal is asking for trouble. For a good /// guide on what to do, see [the floating point /// guide](http://www.floating-point-gui.de/errors/comparison). /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = 1.2331f64; /// let y = 1.2332f64; @@ -115,16 +118,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for conversions to owned values just for the sake + /// ### What it does + /// Checks for conversions to owned values just for the sake /// of a comparison. /// - /// **Why is this bad?** The comparison can operate on a reference, so creating + /// ### Why is this bad? + /// The comparison can operate on a reference, so creating /// an owned value effectively throws it away directly afterwards, which is /// needlessly consuming code and heap space. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = "foo"; /// # let y = String::from("foo"); @@ -142,18 +145,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for getting the remainder of a division by one or minus + /// ### What it does + /// Checks for getting the remainder of a division by one or minus /// one. /// - /// **Why is this bad?** The result for a divisor of one can only ever be zero; for + /// ### Why is this bad? + /// The result for a divisor of one can only ever be zero; for /// minus one it can cause panic/overflow (if the left operand is the minimal value of /// the respective integer type) or results in zero. No one will write such code /// deliberately, unless trying to win an Underhanded Rust Contest. Even for that /// contest, it's probably a bad idea. Use something more underhanded. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// let a = x % 1; @@ -165,17 +168,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the use of bindings with a single leading + /// ### What it does + /// Checks for the use of bindings with a single leading /// underscore. /// - /// **Why is this bad?** A single leading underscore is usually used to indicate + /// ### Why is this bad? + /// A single leading underscore is usually used to indicate /// that a binding will not be used. Using such a binding breaks this /// expectation. /// - /// **Known problems:** The lint does not work properly with desugaring and + /// ### Known problems + /// The lint does not work properly with desugaring and /// macro, it has been allowed in the mean time. /// - /// **Example:** + /// ### Example /// ```rust /// let _x = 0; /// let y = _x + 1; // Here we are using `_x`, even though it has a leading @@ -187,17 +193,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the use of short circuit boolean conditions as + /// ### What it does + /// Checks for the use of short circuit boolean conditions as /// a /// statement. /// - /// **Why is this bad?** Using a short circuit boolean condition as a statement + /// ### Why is this bad? + /// Using a short circuit boolean condition as a statement /// may hide the fact that the second part is executed or not depending on the /// outcome of the first part. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// f() && g(); // We should write `if f() { g(); }`. /// ``` @@ -207,15 +213,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Catch casts from `0` to some pointer type + /// ### What it does + /// Catch casts from `0` to some pointer type /// - /// **Why is this bad?** This generally means `null` and is better expressed as + /// ### Why is this bad? + /// This generally means `null` and is better expressed as /// {`std`, `core`}`::ptr::`{`null`, `null_mut`}. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// let a = 0 as *const u32; @@ -229,18 +234,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for (in-)equality comparisons on floating-point + /// ### What it does + /// Checks for (in-)equality comparisons on floating-point /// value and constant, except in functions called `*eq*` (which probably /// implement equality for a type involving floats). /// - /// **Why is this bad?** Floating point calculations are usually imprecise, so + /// ### Why is this bad? + /// Floating point calculations are usually imprecise, so /// asking if two values are *exactly* equal is asking for trouble. For a good /// guide on what to do, see [the floating point /// guide](http://www.floating-point-gui.de/errors/comparison). /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x: f64 = 1.0; /// const ONE: f64 = 1.00; diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index 050b6805b7c..06fe967dafc 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -18,14 +18,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for structure field patterns bound to wildcards. + /// ### What it does + /// Checks for structure field patterns bound to wildcards. /// - /// **Why is this bad?** Using `..` instead is shorter and leaves the focus on + /// ### Why is this bad? + /// Using `..` instead is shorter and leaves the focus on /// the fields that are actually bound. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # struct Foo { /// # a: i32, @@ -52,14 +52,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for function arguments having the similar names + /// ### What it does + /// Checks for function arguments having the similar names /// differing by an underscore. /// - /// **Why is this bad?** It affects code readability. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// It affects code readability. /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// fn foo(a: i32, _a: i32) {} @@ -73,14 +73,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Detects expressions of the form `--x`. + /// ### What it does + /// Detects expressions of the form `--x`. /// - /// **Why is this bad?** It can mislead C/C++ programmers to think `x` was + /// ### Why is this bad? + /// It can mislead C/C++ programmers to think `x` was /// decremented. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let mut x = 3; /// --x; @@ -91,14 +91,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns on hexadecimal literals with mixed-case letter + /// ### What it does + /// Warns on hexadecimal literals with mixed-case letter /// digits. /// - /// **Why is this bad?** It looks confusing. + /// ### Why is this bad? + /// It looks confusing. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let y = 0x1a9BAcD; @@ -112,14 +112,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns if literal suffixes are not separated by an + /// ### What it does + /// Warns if literal suffixes are not separated by an /// underscore. /// - /// **Why is this bad?** It is much less readable. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// It is much less readable. /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let y = 123832i32; @@ -133,17 +133,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns if an integral constant literal starts with `0`. + /// ### What it does + /// Warns if an integral constant literal starts with `0`. /// - /// **Why is this bad?** In some languages (including the infamous C language + /// ### Why is this bad? + /// In some languages (including the infamous C language /// and most of its /// family), this marks an octal constant. In Rust however, this is a decimal /// constant. This could /// be confusing for both the writer and a reader of the constant. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// In Rust: /// ```rust @@ -171,13 +171,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Warns if a generic shadows a built-in type. - /// - /// **Why is this bad?** This gives surprising type errors. + /// ### What it does + /// Warns if a generic shadows a built-in type. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This gives surprising type errors. /// - /// **Example:** + /// ### Example /// /// ```ignore /// impl Foo { @@ -192,14 +192,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for patterns in the form `name @ _`. + /// ### What it does + /// Checks for patterns in the form `name @ _`. /// - /// **Why is this bad?** It's almost always more readable to just use direct + /// ### Why is this bad? + /// It's almost always more readable to just use direct /// bindings. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let v = Some("abc"); /// @@ -221,19 +221,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for tuple patterns with a wildcard + /// ### What it does + /// Checks for tuple patterns with a wildcard /// pattern (`_`) is next to a rest pattern (`..`). /// /// _NOTE_: While `_, ..` means there is at least one element left, `..` /// means there are 0 or more elements left. This can make a difference /// when refactoring, but shouldn't result in errors in the refactored code, /// since the wildcard pattern isn't used anyway. - /// **Why is this bad?** The wildcard pattern is unneeded as the rest pattern + /// ### Why is this bad? + /// The wildcard pattern is unneeded as the rest pattern /// can match that element as well. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # struct TupleStruct(u32, u32, u32); /// # let t = TupleStruct(1, 2, 3); diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 59cbc481ed4..5b2584d43a1 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -13,16 +13,13 @@ use rustc_span::Span; use rustc_typeck::hir_ty_to_ty; declare_clippy_lint! { - /// **What it does:** - /// + /// ### What it does /// Suggests the use of `const` in functions and methods where possible. /// - /// **Why is this bad?** - /// + /// ### Why is this bad? /// Not having the function const prevents callers of the function from being const as well. /// - /// **Known problems:** - /// + /// ### Known problems /// Const functions are currently still being worked on, with some features only being available /// on nightly. This lint does not consider all edge cases currently and the suggestions may be /// incorrect if you are using this lint on stable. @@ -42,8 +39,7 @@ declare_clippy_lint! { /// can't be const as it calls a non-const function. Making `a` const and running Clippy again, /// will suggest to make `b` const, too. /// - /// **Example:** - /// + /// ### Example /// ```rust /// # struct Foo { /// # random_number: usize, diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index ec1572c26c2..aeed8268902 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -17,15 +17,15 @@ use rustc_span::source_map::Span; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Warns if there is missing doc for any documentable item + /// ### What it does + /// Warns if there is missing doc for any documentable item /// (public or private). /// - /// **Why is this bad?** Doc is good. *rustc* has a `MISSING_DOCS` + /// ### Why is this bad? + /// Doc is good. *rustc* has a `MISSING_DOCS` /// allowed-by-default lint for /// public members, but has no way to enforce documentation of private items. /// This lint fixes that. - /// - /// **Known problems:** None. pub MISSING_DOCS_IN_PRIVATE_ITEMS, restriction, "detects missing documentation for public and private members" diff --git a/clippy_lints/src/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 59565350f72..9d27870321c 100644 --- a/clippy_lints/src/missing_enforced_import_rename.rs +++ b/clippy_lints/src/missing_enforced_import_rename.rs @@ -10,17 +10,16 @@ use rustc_span::Symbol; use crate::utils::conf::Rename; declare_clippy_lint! { - /// **What it does:** Checks for imports that do not rename the item as specified + /// ### What it does + /// Checks for imports that do not rename the item as specified /// in the `enforce-import-renames` config option. /// - /// **Why is this bad?** Consistency is important, if a project has defined import + /// ### Why is this bad? + /// Consistency is important, if a project has defined import /// renames they should be followed. More practically, some item names are too /// vague outside of their defining scope this can enforce a more meaningful naming. /// - /// **Known problems:** None - /// - /// **Example:** - /// + /// ### Example /// An example clippy.toml configuration: /// ```toml /// # clippy.toml diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 041fe64a1a9..be5b4b4006f 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -7,10 +7,12 @@ use rustc_span::source_map::Span; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** it lints if an exported function, method, trait method with default impl, + /// ### What it does + /// it lints if an exported function, method, trait method with default impl, /// or trait method impl is not `#[inline]`. /// - /// **Why is this bad?** In general, it is not. Functions can be inlined across + /// ### Why is this bad? + /// In general, it is not. Functions can be inlined across /// crates when that's profitable as long as any form of LTO is used. When LTO is disabled, /// functions that are not `#[inline]` cannot be inlined across crates. Certain types of crates /// might intend for most of the methods in their public API to be able to be inlined across @@ -18,9 +20,7 @@ declare_clippy_lint! { /// sense. It allows the crate to require all exported methods to be `#[inline]` by default, and /// then opt out for specific methods where this might not make sense. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// pub fn foo() {} // missing #[inline] /// fn ok() {} // ok diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index 1414fdc1b11..2d14943b56c 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -9,18 +9,18 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::fmt::Display; declare_clippy_lint! { - /// **What it does:** Checks for modulo arithmetic. + /// ### What it does + /// Checks for modulo arithmetic. /// - /// **Why is this bad?** The results of modulo (%) operation might differ + /// ### Why is this bad? + /// The results of modulo (%) operation might differ /// depending on the language, when negative numbers are involved. /// If you interop with different languages it might be beneficial /// to double check all places that use modulo arithmetic. /// /// For example, in Rust `17 % -3 = 2`, but in Python `17 % -3 = -1`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = -17 % 3; /// ``` diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index f5ce3e32551..1c61970fdc8 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -13,17 +13,20 @@ use if_chain::if_chain; use itertools::Itertools; declare_clippy_lint! { - /// **What it does:** Checks to see if multiple versions of a crate are being + /// ### What it does + /// Checks to see if multiple versions of a crate are being /// used. /// - /// **Why is this bad?** This bloats the size of targets, and can lead to + /// ### Why is this bad? + /// This bloats the size of targets, and can lead to /// confusing error messages when structs or traits are used interchangeably /// between different versions of a crate. /// - /// **Known problems:** Because this can be caused purely by the dependencies + /// ### Known problems + /// Because this can be caused purely by the dependencies /// themselves, it's not always possible to fix this issue. /// - /// **Example:** + /// ### Example /// ```toml /// # This will pull in both winapi v0.3.x and v0.2.x, triggering a warning. /// [dependencies] diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 68f7cdf6ea0..2c7681c45a4 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -10,18 +10,21 @@ use rustc_span::symbol::sym; use std::iter; declare_clippy_lint! { - /// **What it does:** Checks for sets/maps with mutable key types. + /// ### What it does + /// Checks for sets/maps with mutable key types. /// - /// **Why is this bad?** All of `HashMap`, `HashSet`, `BTreeMap` and + /// ### Why is this bad? + /// All of `HashMap`, `HashSet`, `BTreeMap` and /// `BtreeSet` rely on either the hash or the order of keys be unchanging, /// so having types with interior mutability is a bad idea. /// - /// **Known problems:** It's correct to use a struct, that contains interior mutability + /// ### Known problems + /// It's correct to use a struct, that contains interior mutability /// as a key, when its `Hash` implementation doesn't access any of the interior mutable types. /// However, this lint is unable to recognize this, so it causes a false positive in theses cases. /// The `bytes` crate is a great example of this. /// - /// **Example:** + /// ### Example /// ```rust /// use std::cmp::{PartialEq, Eq}; /// use std::collections::HashSet; diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 4b9c51d0c16..d5032c5ba7f 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -9,15 +9,15 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for instances of `mut mut` references. + /// ### What it does + /// Checks for instances of `mut mut` references. /// - /// **Why is this bad?** Multiple `mut`s don't add anything meaningful to the + /// ### Why is this bad? + /// Multiple `mut`s don't add anything meaningful to the /// source. This is either a copy'n'paste error, or it shows a fundamental /// misunderstanding of references. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let mut y = 1; /// let x = &mut &mut y; diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs index b9ba74c7d02..85e870632a5 100644 --- a/clippy_lints/src/mut_mutex_lock.rs +++ b/clippy_lints/src/mut_mutex_lock.rs @@ -8,17 +8,16 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `&mut Mutex::lock` calls + /// ### What it does + /// Checks for `&mut Mutex::lock` calls /// - /// **Why is this bad?** `Mutex::lock` is less efficient than + /// ### Why is this bad? + /// `Mutex::lock` is less efficient than /// calling `Mutex::get_mut`. In addition you also have a statically /// guarantee that the mutex isn't locked, instead of just a runtime /// guarantee. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// use std::sync::{Arc, Mutex}; /// diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 6efe8ffcde0..8d5d7951fc5 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -7,15 +7,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::iter; declare_clippy_lint! { - /// **What it does:** Detects passing a mutable reference to a function that only + /// ### What it does + /// Detects passing a mutable reference to a function that only /// requires an immutable reference. /// - /// **Why is this bad?** The mutable reference rules out all other references to + /// ### Why is this bad? + /// The mutable reference rules out all other references to /// the value. Also the code misleads about the intent of the call site. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// // Bad /// my_vec.push(&mut value) diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 81bf853300f..ee50891cc31 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -9,17 +9,17 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for function/method calls with a mutable + /// ### What it does + /// Checks for function/method calls with a mutable /// parameter in `debug_assert!`, `debug_assert_eq!` and `debug_assert_ne!` macros. /// - /// **Why is this bad?** In release builds `debug_assert!` macros are optimized out by the + /// ### Why is this bad? + /// In release builds `debug_assert!` macros are optimized out by the /// compiler. /// Therefore mutating something in a `debug_assert!` macro results in different behaviour /// between a release and debug build. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// debug_assert_eq!(vec![3].pop(), Some(3)); /// // or diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 354e2c3fb74..436ceec6cfa 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -10,17 +10,20 @@ use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for usages of `Mutex` where an atomic will do. + /// ### What it does + /// Checks for usages of `Mutex` where an atomic will do. /// - /// **Why is this bad?** Using a mutex just to make access to a plain bool or + /// ### Why is this bad? + /// Using a mutex just to make access to a plain bool or /// reference sequential is shooting flies with cannons. /// `std::sync::atomic::AtomicBool` and `std::sync::atomic::AtomicPtr` are leaner and /// faster. /// - /// **Known problems:** This lint cannot detect if the mutex is actually used + /// ### Known problems + /// This lint cannot detect if the mutex is actually used /// for waiting before a critical section. /// - /// **Example:** + /// ### Example /// ```rust /// # let y = true; /// @@ -38,17 +41,20 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usages of `Mutex` where `X` is an integral + /// ### What it does + /// Checks for usages of `Mutex` where `X` is an integral /// type. /// - /// **Why is this bad?** Using a mutex just to make access to a plain integer + /// ### Why is this bad? + /// Using a mutex just to make access to a plain integer /// sequential is /// shooting flies with cannons. `std::sync::atomic::AtomicUsize` is leaner and faster. /// - /// **Known problems:** This lint cannot detect if the mutex is actually used + /// ### Known problems + /// This lint cannot detect if the mutex is actually used /// for waiting before a critical section. /// - /// **Example:** + /// ### Example /// ```rust /// # use std::sync::Mutex; /// let x = Mutex::new(0usize); diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index fe3c4455be5..9a3d9383cd9 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -9,13 +9,13 @@ use rustc_span::symbol::kw; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** The lint checks for `self` in fn parameters that + /// ### What it does + /// The lint checks for `self` in fn parameters that /// specify the `Self`-type explicitly - /// **Why is this bad?** Increases the amount and decreases the readability of code + /// ### Why is this bad? + /// Increases the amount and decreases the readability of code /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// enum ValType { /// I32, diff --git a/clippy_lints/src/needless_bitwise_bool.rs b/clippy_lints/src/needless_bitwise_bool.rs index b30bfbd4294..203da29cb91 100644 --- a/clippy_lints/src/needless_bitwise_bool.rs +++ b/clippy_lints/src/needless_bitwise_bool.rs @@ -9,20 +9,19 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Checks for uses of bitwise and/or operators between booleans, where performance may be improved by using /// a lazy and. /// - /// **Why is this bad?** + /// ### Why is this bad? /// The bitwise operators do not support short-circuiting, so it may hinder code performance. /// Additionally, boolean logic "masked" as bitwise logic is not caught by lints like `unnecessary_fold` /// - /// **Known problems:** + /// ### Known problems /// This lint evaluates only when the right side is determined to have no side effects. At this time, that /// determination is quite conservative. /// - /// **Example:** - /// + /// ### Example /// ```rust /// let (x,y) = (true, false); /// if x & !y {} // where both x and y are booleans diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 780690548e5..36f2829a5b9 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -15,17 +15,20 @@ use rustc_span::source_map::Spanned; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for expressions of the form `if c { true } else { + /// ### What it does + /// Checks for expressions of the form `if c { true } else { /// false }` (or vice versa) and suggests using the condition directly. /// - /// **Why is this bad?** Redundant code. + /// ### Why is this bad? + /// Redundant code. /// - /// **Known problems:** Maybe false positives: Sometimes, the two branches are + /// ### Known problems + /// Maybe false positives: Sometimes, the two branches are /// painstakingly documented (which we, of course, do not detect), so they *may* /// have some value. Even then, the documentation can be rewritten to match the /// shorter code. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// if x { /// false @@ -43,15 +46,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for expressions of the form `x == true`, + /// ### What it does + /// Checks for expressions of the form `x == true`, /// `x != true` and order comparisons such as `x < true` (or vice versa) and /// suggest using the variable directly. /// - /// **Why is this bad?** Unnecessary code. + /// ### Why is this bad? + /// Unnecessary code. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// if x == true {} /// if y == false {} diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index dd1dfa2bdfb..3f0b23ee4d3 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -17,15 +17,15 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for address of operations (`&`) that are going to + /// ### What it does + /// Checks for address of operations (`&`) that are going to /// be dereferenced immediately by the compiler. /// - /// **Why is this bad?** Suggests that the receiver of the expression borrows + /// ### Why is this bad? + /// Suggests that the receiver of the expression borrows /// the expression. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let x: &i32 = &&&&&&5; @@ -39,13 +39,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `ref` bindings which create a reference to a reference. - /// - /// **Why is this bad?** The address-of operator at the use site is clearer about the need for a reference. + /// ### What it does + /// Checks for `ref` bindings which create a reference to a reference. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// The address-of operator at the use site is clearer about the need for a reference. /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let x = Some(""); diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 0e976b130eb..36879eda7c0 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -7,12 +7,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for bindings that destructure a reference and borrow the inner + /// ### What it does + /// Checks for bindings that destructure a reference and borrow the inner /// value with `&ref`. /// - /// **Why is this bad?** This pattern has no effect in almost all cases. + /// ### Why is this bad? + /// This pattern has no effect in almost all cases. /// - /// **Known problems:** In some cases, `&ref` is needed to avoid a lifetime mismatch error. + /// ### Known problems + /// In some cases, `&ref` is needed to avoid a lifetime mismatch error. /// Example: /// ```rust /// fn foo(a: &Option, b: &Option) { @@ -23,7 +26,7 @@ declare_clippy_lint! { /// } /// ``` /// - /// **Example:** + /// ### Example /// Bad: /// ```rust /// let mut v = Vec::::new(); diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 1d19413e0d0..5088b8bb0d3 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -42,20 +42,20 @@ use rustc_span::source_map::{original_sp, DUMMY_SP}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** The lint checks for `if`-statements appearing in loops + /// ### What it does + /// The lint checks for `if`-statements appearing in loops /// that contain a `continue` statement in either their main blocks or their /// `else`-blocks, when omitting the `else`-block possibly with some /// rearrangement of code can make the code easier to understand. /// - /// **Why is this bad?** Having explicit `else` blocks for `if` statements + /// ### Why is this bad? + /// Having explicit `else` blocks for `if` statements /// containing `continue` in their THEN branch adds unnecessary branching and /// nesting to the code. Having an else block containing just `continue` can /// also be better written by grouping the statements following the whole `if` /// statement within the THEN block and omitting the else block completely. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// # fn condition() -> bool { false } /// # fn update_condition() {} diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index a723a472a25..d9aa42fe8ee 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -16,18 +16,17 @@ use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::has_iter_method; declare_clippy_lint! { - /// **What it does:** Checks for usage of `for_each` that would be more simply written as a + /// ### What it does + /// Checks for usage of `for_each` that would be more simply written as a /// `for` loop. /// - /// **Why is this bad?** `for_each` may be used after applying iterator transformers like + /// ### Why is this bad? + /// `for_each` may be used after applying iterator transformers like /// `filter` for better readability and performance. It may also be used to fit a simple /// operation on one line. /// But when none of these apply, a simple `for` loop is more idiomatic. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let v = vec![0, 1, 2]; /// v.iter().for_each(|elem| { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 283b1847b6c..03eeb54d8d1 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -24,20 +24,22 @@ use rustc_typeck::expr_use_visitor as euv; use std::borrow::Cow; declare_clippy_lint! { - /// **What it does:** Checks for functions taking arguments by value, but not + /// ### What it does + /// Checks for functions taking arguments by value, but not /// consuming them in its /// body. /// - /// **Why is this bad?** Taking arguments by reference is more flexible and can + /// ### Why is this bad? + /// Taking arguments by reference is more flexible and can /// sometimes avoid /// unnecessary allocations. /// - /// **Known problems:** + /// ### Known problems /// * This lint suggests taking an argument by reference, /// however sometimes it is better to let users decide the argument type /// (by using `Borrow` trait, for example), depending on how the function is used. /// - /// **Example:** + /// ### Example /// ```rust /// fn foo(v: Vec) { /// assert_eq!(v.len(), 42); diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index c64491c63e2..42e48336e15 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -10,15 +10,13 @@ use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Suggests alternatives for useless applications of `?` in terminating expressions /// - /// **Why is this bad?** There's no reason to use `?` to short-circuit when execution of the body will end there anyway. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// There's no reason to use `?` to short-circuit when execution of the body will end there anyway. /// + /// ### Example /// ```rust /// struct TO { /// magic: Option, diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 8f325404deb..2a33b7392ca 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -5,18 +5,18 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for needlessly including a base struct on update + /// ### What it does + /// Checks for needlessly including a base struct on update /// when all fields are changed anyway. /// /// This lint is not applied to structs marked with /// [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html). /// - /// **Why is this bad?** This will cost resources (because the base has to be + /// ### Why is this bad? + /// This will cost resources (because the base has to be /// somewhere), and make the code less readable. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # struct Point { /// # x: i32, diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index c824f6f54b5..6ad49b70605 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -8,19 +8,16 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Checks for the usage of negated comparison operators on types which only implement /// `PartialOrd` (e.g., `f64`). /// - /// **Why is this bad?** + /// ### Why is this bad? /// These operators make it easy to forget that the underlying types actually allow not only three /// potential Orderings (Less, Equal, Greater) but also a fourth one (Uncomparable). This is /// especially easy to miss if the operator based comparison result is negated. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// use std::cmp::Ordering; /// diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index d5e1ea6d242..fa36d8fb1b3 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -7,13 +7,16 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for multiplication by -1 as a form of negation. + /// ### What it does + /// Checks for multiplication by -1 as a form of negation. /// - /// **Why is this bad?** It's more readable to just negate. + /// ### Why is this bad? + /// It's more readable to just negate. /// - /// **Known problems:** This only catches integers (for now). + /// ### Known problems + /// This only catches integers (for now). /// - /// **Example:** + /// ### Example /// ```ignore /// x * -1 /// ``` diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index bc409dd6efb..5c63d245bf1 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -13,18 +13,17 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for types with a `fn new() -> Self` method and no + /// ### What it does + /// Checks for types with a `fn new() -> Self` method and no /// implementation of /// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html). /// - /// **Why is this bad?** The user might expect to be able to use + /// ### Why is this bad? + /// The user might expect to be able to use /// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html) as the /// type can be constructed without arguments. /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** - /// + /// ### Example /// ```ignore /// struct Foo(Bar); /// diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 910b0536092..e07518b2586 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -9,15 +9,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::ops::Deref; declare_clippy_lint! { - /// **What it does:** Checks for statements which have no effect. + /// ### What it does + /// Checks for statements which have no effect. /// - /// **Why is this bad?** Similar to dead code, these statements are actually + /// ### Why is this bad? + /// Similar to dead code, these statements are actually /// executed. However, as they have no effect, all they do is make the code less /// readable. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// 0; /// ``` @@ -27,15 +27,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for expression statements that can be reduced to a + /// ### What it does + /// Checks for expression statements that can be reduced to a /// sub-expression. /// - /// **Why is this bad?** Expressions by themselves often have no side-effects. + /// ### Why is this bad? + /// Expressions by themselves often have no side-effects. /// Having such expressions reduces readability. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// compute_array()[0]; /// ``` diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index d775cd7c7f7..aa3067876eb 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -24,10 +24,12 @@ use rustc_typeck::hir_ty_to_ty; // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. declare_clippy_lint! { - /// **What it does:** Checks for declaration of `const` items which is interior + /// ### What it does + /// Checks for declaration of `const` items which is interior /// mutable (e.g., contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.). /// - /// **Why is this bad?** Consts are copied everywhere they are referenced, i.e., + /// ### Why is this bad? + /// Consts are copied everywhere they are referenced, i.e., /// every time you refer to the const a fresh instance of the `Cell` or `Mutex` /// or `AtomicXxxx` will be created, which defeats the whole purpose of using /// these types in the first place. @@ -35,7 +37,8 @@ declare_clippy_lint! { /// The `const` should better be replaced by a `static` item if a global /// variable is wanted, or replaced by a `const fn` if a constructor is wanted. /// - /// **Known problems:** A "non-constant" const item is a legacy way to supply an + /// ### Known problems + /// A "non-constant" const item is a legacy way to supply an /// initialized value to downstream `static` items (e.g., the /// `std::sync::ONCE_INIT` constant). In this case the use of `const` is legit, /// and this lint should be suppressed. @@ -52,7 +55,7 @@ declare_clippy_lint! { /// the interior mutable field is used or not. See issues /// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and /// - /// **Example:** + /// ### Example /// ```rust /// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; /// @@ -74,17 +77,20 @@ declare_clippy_lint! { // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. declare_clippy_lint! { - /// **What it does:** Checks if `const` items which is interior mutable (e.g., + /// ### What it does + /// Checks if `const` items which is interior mutable (e.g., /// contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.) has been borrowed directly. /// - /// **Why is this bad?** Consts are copied everywhere they are referenced, i.e., + /// ### Why is this bad? + /// Consts are copied everywhere they are referenced, i.e., /// every time you refer to the const a fresh instance of the `Cell` or `Mutex` /// or `AtomicXxxx` will be created, which defeats the whole purpose of using /// these types in the first place. /// /// The `const` value should be stored inside a `static` item. /// - /// **Known problems:** When an enum has variants with interior mutability, use of its non + /// ### Known problems + /// When an enum has variants with interior mutability, use of its non /// interior mutable variants can generate false positives. See issue /// [#3962](https://github.com/rust-lang/rust-clippy/issues/3962) /// @@ -93,7 +99,7 @@ declare_clippy_lint! { /// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and /// [#3825](https://github.com/rust-lang/rust-clippy/issues/3825) /// - /// **Example:** + /// ### Example /// ```rust /// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; /// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12); diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 7183a7c3858..dc55b103eb6 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -12,14 +12,14 @@ use rustc_span::symbol::{Ident, Symbol}; use std::cmp::Ordering; declare_clippy_lint! { - /// **What it does:** Checks for names that are very similar and thus confusing. + /// ### What it does + /// Checks for names that are very similar and thus confusing. /// - /// **Why is this bad?** It's hard to distinguish between names that differ only + /// ### Why is this bad? + /// It's hard to distinguish between names that differ only /// by a single character. /// - /// **Known problems:** None? - /// - /// **Example:** + /// ### Example /// ```ignore /// let checked_exp = something; /// let checked_expr = something_else; @@ -30,15 +30,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for too many variables whose name consists of a + /// ### What it does + /// Checks for too many variables whose name consists of a /// single character. /// - /// **Why is this bad?** It's hard to memorize what a variable means without a + /// ### Why is this bad? + /// It's hard to memorize what a variable means without a /// descriptive name. /// - /// **Known problems:** None? - /// - /// **Example:** + /// ### Example /// ```ignore /// let (a, b, c, d, e, f, g) = (...); /// ``` @@ -48,15 +48,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks if you have variables whose name consists of just + /// ### What it does + /// Checks if you have variables whose name consists of just /// underscores and digits. /// - /// **Why is this bad?** It's hard to memorize what a variable means without a + /// ### Why is this bad? + /// It's hard to memorize what a variable means without a /// descriptive name. /// - /// **Known problems:** None? - /// - /// **Example:** + /// ### Example /// ```rust /// let _1 = 1; /// let ___1 = 1; diff --git a/clippy_lints/src/non_octal_unix_permissions.rs b/clippy_lints/src/non_octal_unix_permissions.rs index a83daea97bf..3b74f69d375 100644 --- a/clippy_lints/src/non_octal_unix_permissions.rs +++ b/clippy_lints/src/non_octal_unix_permissions.rs @@ -9,15 +9,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for non-octal values used to set Unix file permissions. + /// ### What it does + /// Checks for non-octal values used to set Unix file permissions. /// - /// **Why is this bad?** They will be converted into octal, creating potentially + /// ### Why is this bad? + /// They will be converted into octal, creating potentially /// unintended file permissions. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// use std::fs::OpenOptions; /// use std::os::unix::fs::OpenOptionsExt; diff --git a/clippy_lints/src/nonstandard_macro_braces.rs b/clippy_lints/src/nonstandard_macro_braces.rs index 043e7fa30d6..dbe9cbe0ded 100644 --- a/clippy_lints/src/nonstandard_macro_braces.rs +++ b/clippy_lints/src/nonstandard_macro_braces.rs @@ -13,16 +13,14 @@ use rustc_span::Span; use serde::{de, Deserialize}; declare_clippy_lint! { - /// **What it does:** Checks that common macros are used with consistent bracing. + /// ### What it does + /// Checks that common macros are used with consistent bracing. /// - /// **Why is this bad?** This is mostly a consistency lint although using () or [] + /// ### Why is this bad? + /// This is mostly a consistency lint although using () or [] /// doesn't give you a semicolon in item position, which can be unexpected. /// - /// **Known problems:** - /// None - /// - /// **Example:** - /// + /// ### Example /// ```rust /// vec!{1, 2, 3}; /// ``` diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index fded48038e3..4064d94da2a 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -8,15 +8,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{Span, Spanned}; declare_clippy_lint! { - /// **What it does:** Checks for duplicate open options as well as combinations + /// ### What it does + /// Checks for duplicate open options as well as combinations /// that make no sense. /// - /// **Why is this bad?** In the best case, the code will be harder to read than + /// ### Why is this bad? + /// In the best case, the code will be harder to read than /// necessary. I don't know the worst case. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// use std::fs::OpenOptions; /// diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index b6f518661bd..d7306628030 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -7,17 +7,16 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for usage of `option_env!(...).unwrap()` and + /// ### What it does + /// Checks for usage of `option_env!(...).unwrap()` and /// suggests usage of the `env!` macro. /// - /// **Why is this bad?** Unwrapping the result of `option_env!` will panic + /// ### Why is this bad? + /// Unwrapping the result of `option_env!` will panic /// at run-time if the environment variable doesn't exist, whereas `env!` /// catches it at compile-time. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,no_run /// let _ = option_env!("HOME").unwrap(); /// ``` diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index b2be35bdddb..7aef3a5f34c 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -12,24 +12,23 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Lints usage of `if let Some(v) = ... { y } else { x }` which is more /// idiomatically done with `Option::map_or` (if the else bit is a pure /// expression) or `Option::map_or_else` (if the else bit is an impure /// expression). /// - /// **Why is this bad?** + /// ### Why is this bad? /// Using the dedicated functions of the Option type is clearer and /// more concise than an `if let` expression. /// - /// **Known problems:** + /// ### Known problems /// This lint uses a deliberately conservative metric for checking /// if the inside of either body contains breaks or continues which will /// cause it to not suggest a fix if either block contains a loop with /// continues or breaks contained within the loop. /// - /// **Example:** - /// + /// ### Example /// ```rust /// # let optional: Option = Some(0); /// # fn do_complicated_function() -> u32 { 5 }; diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index e222782c2cc..34755afdb72 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -6,14 +6,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Detects classic underflow/overflow checks. + /// ### What it does + /// Detects classic underflow/overflow checks. /// - /// **Why is this bad?** Most classic C underflow/overflow checks will fail in + /// ### Why is this bad? + /// Most classic C underflow/overflow checks will fail in /// Rust. Users can use functions like `overflowing_*` and `wrapping_*` instead. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let a = 1; /// # let b = 2; diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index cef74d87e7c..e2b6ba8e2d2 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -8,14 +8,16 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result. + /// ### What it does + /// Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result. /// - /// **Why is this bad?** For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided. + /// ### Why is this bad? + /// For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided. /// - /// **Known problems:** Functions called from a function returning a `Result` may invoke a panicking macro. This is not checked. - /// - /// **Example:** + /// ### Known problems + /// Functions called from a function returning a `Result` may invoke a panicking macro. This is not checked. /// + /// ### Example /// ```rust /// fn result_with_panic() -> Result /// { diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index dc28874c16e..d8d9081d6f1 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -7,13 +7,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for usage of `panic!`. + /// ### What it does + /// Checks for usage of `panic!`. /// - /// **Why is this bad?** `panic!` will stop the execution of the executable + /// ### Why is this bad? + /// `panic!` will stop the execution of the executable /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```no_run /// panic!("even with a good reason"); /// ``` @@ -23,13 +23,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `unimplemented!`. - /// - /// **Why is this bad?** This macro should not be present in production code + /// ### What it does + /// Checks for usage of `unimplemented!`. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This macro should not be present in production code /// - /// **Example:** + /// ### Example /// ```no_run /// unimplemented!(); /// ``` @@ -39,13 +39,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `todo!`. + /// ### What it does + /// Checks for usage of `todo!`. /// - /// **Why is this bad?** This macro should not be present in production code + /// ### Why is this bad? + /// This macro should not be present in production code /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```no_run /// todo!(); /// ``` @@ -55,13 +55,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `unreachable!`. - /// - /// **Why is this bad?** This macro can cause code to panic + /// ### What it does + /// Checks for usage of `unreachable!`. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This macro can cause code to panic /// - /// **Example:** + /// ### Example /// ```no_run /// unreachable!(); /// ``` diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 1251ddd9a02..4ec493e5f45 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -7,16 +7,16 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`. + /// ### What it does + /// Checks for manual re-implementations of `PartialEq::ne`. /// - /// **Why is this bad?** `PartialEq::ne` is required to always return the + /// ### Why is this bad? + /// `PartialEq::ne` is required to always return the /// negated result of `PartialEq::eq`, which is exactly what the default /// implementation does. Therefore, there should never be any need to /// re-implement it. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// struct Foo; /// diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index f6a70478559..f738ac25417 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -20,15 +20,18 @@ use rustc_target::spec::abi::Abi; use rustc_target::spec::Target; declare_clippy_lint! { - /// **What it does:** Checks for functions taking arguments by reference, where + /// ### What it does + /// Checks for functions taking arguments by reference, where /// the argument type is `Copy` and small enough to be more efficient to always /// pass by value. /// - /// **Why is this bad?** In many calling conventions instances of structs will + /// ### Why is this bad? + /// In many calling conventions instances of structs will /// be passed through registers if they fit into two or less general purpose /// registers. /// - /// **Known problems:** This lint is target register size dependent, it is + /// ### Known problems + /// This lint is target register size dependent, it is /// limited to 32-bit to try and reduce portability problems between 32 and /// 64-bit, but if you are compiling for 8 or 16-bit targets then the limit /// will be different. @@ -50,7 +53,7 @@ declare_clippy_lint! { /// that explains a real case in which this false positive /// led to an **undefined behaviour** introduced with unsafe code. /// - /// **Example:** + /// ### Example /// /// ```rust /// // Bad @@ -67,18 +70,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for functions taking arguments by value, where + /// ### What it does + /// Checks for functions taking arguments by value, where /// the argument type is `Copy` and large enough to be worth considering /// passing by reference. Does not trigger if the function is being exported, /// because that might induce API breakage, if the parameter is declared as mutable, /// or if the argument is a `self`. /// - /// **Why is this bad?** Arguments passed by value might result in an unnecessary + /// ### Why is this bad? + /// Arguments passed by value might result in an unnecessary /// shallow copy, taking up more space in the stack and requiring a call to /// `memcpy`, which can be expensive. /// - /// **Example:** - /// + /// ### Example /// ```rust /// #[derive(Clone, Copy)] /// struct TooLarge([u8; 2048]); diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 00245926381..3df7a72d295 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -10,15 +10,15 @@ use rustc_span::symbol::sym; use std::path::{Component, Path}; declare_clippy_lint! { - /// **What it does:*** Checks for [push](https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.push) + /// ### What it does + ///* Checks for [push](https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.push) /// calls on `PathBuf` that can cause overwrites. /// - /// **Why is this bad?** Calling `push` with a root path at the start can overwrite the + /// ### Why is this bad? + /// Calling `push` with a root path at the start can overwrite the /// previous defined path. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// use std::path::PathBuf; /// diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index ea4065d371b..4534f6e2516 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -13,7 +13,8 @@ use rustc_span::source_map::Span; use std::iter; declare_clippy_lint! { - /// **What it does:** Checks for patterns that aren't exact representations of the types + /// ### What it does + /// Checks for patterns that aren't exact representations of the types /// they are applied to. /// /// To satisfy this lint, you will have to adjust either the expression that is matched @@ -32,14 +33,12 @@ declare_clippy_lint! { /// this lint can still be used to highlight areas of interest and ensure a good understanding /// of ownership semantics. /// - /// **Why is this bad?** It isn't bad in general. But in some contexts it can be desirable + /// ### Why is this bad? + /// It isn't bad in general. But in some contexts it can be desirable /// because it increases ownership hints in the code, and will guard against some changes /// in ownership. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// This example shows the basic adjustments necessary to satisfy the lint. Note how /// the matched expression is explicitly dereferenced with `*` and the `inner` variable /// is bound to a shared borrow via `ref inner`. diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index 9cf00c953b9..1a8da00d9d6 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -25,7 +25,8 @@ const ALLOWED_ODD_FUNCTIONS: [&str; 14] = [ ]; declare_clippy_lint! { - /// **What it does:** Checks for operations where precedence may be unclear + /// ### What it does + /// Checks for operations where precedence may be unclear /// and suggests to add parentheses. Currently it catches the following: /// * mixed usage of arithmetic and bit shifting/combining operators without /// parentheses @@ -33,13 +34,12 @@ declare_clippy_lint! { /// numeric literal) /// followed by a method call /// - /// **Why is this bad?** Not everyone knows the precedence of those operators by + /// ### Why is this bad? + /// Not everyone knows the precedence of those operators by /// heart, so expressions like these may trip others trying to reason about the /// code. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7 /// * `-1i32.abs()` equals -1, while `(-1i32).abs()` equals 1 pub PRECEDENCE, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index b15447622a8..c0d1f1eb6e6 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -20,16 +20,19 @@ use rustc_span::{sym, MultiSpan}; use std::borrow::Cow; declare_clippy_lint! { - /// **What it does:** This lint checks for function arguments of type `&String` + /// ### What it does + /// This lint checks for function arguments of type `&String` /// or `&Vec` unless the references are mutable. It will also suggest you /// replace `.clone()` calls with the appropriate `.to_owned()`/`to_string()` /// calls. /// - /// **Why is this bad?** Requiring the argument to be of the specific size + /// ### Why is this bad? + /// Requiring the argument to be of the specific size /// makes the function less useful for no benefit; slices in the form of `&[T]` /// or `&str` usually suffice and can be obtained from other types, too. /// - /// **Known problems:** The lint does not follow data. So if you have an + /// ### Known problems + /// The lint does not follow data. So if you have an /// argument `x` and write `let y = x; y.clone()` the lint will not suggest /// changing that `.clone()` to `.to_owned()`. /// @@ -59,7 +62,7 @@ declare_clippy_lint! { /// other crates referencing it, of which you may not be aware. Carefully /// deprecate the function before applying the lint suggestions in this case. /// - /// **Example:** + /// ### Example /// ```ignore /// // Bad /// fn foo(&Vec) { .. } @@ -73,15 +76,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint checks for equality comparisons with `ptr::null` + /// ### What it does + /// This lint checks for equality comparisons with `ptr::null` /// - /// **Why is this bad?** It's easier and more readable to use the inherent + /// ### Why is this bad? + /// It's easier and more readable to use the inherent /// `.is_null()` /// method instead /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// // Bad /// if x == ptr::null { @@ -99,19 +102,22 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint checks for functions that take immutable + /// ### What it does + /// This lint checks for functions that take immutable /// references and return mutable ones. /// - /// **Why is this bad?** This is trivially unsound, as one can create two + /// ### Why is this bad? + /// This is trivially unsound, as one can create two /// mutable references from the same (immutable!) source. /// This [error](https://github.com/rust-lang/rust/issues/39465) /// actually lead to an interim Rust release 1.15.1. /// - /// **Known problems:** To be on the conservative side, if there's at least one + /// ### Known problems + /// To be on the conservative side, if there's at least one /// mutable reference with the output lifetime, this lint will not trigger. /// In practice, this case is unlikely anyway. /// - /// **Example:** + /// ### Example /// ```ignore /// fn foo(&Foo) -> &mut Bar { .. } /// ``` @@ -121,13 +127,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint checks for invalid usages of `ptr::null`. - /// - /// **Why is this bad?** This causes undefined behavior. + /// ### What it does + /// This lint checks for invalid usages of `ptr::null`. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This causes undefined behavior. /// - /// **Example:** + /// ### Example /// ```ignore /// // Bad. Undefined behavior /// unsafe { std::slice::from_raw_parts(ptr::null(), 0); } diff --git a/clippy_lints/src/ptr_eq.rs b/clippy_lints/src/ptr_eq.rs index 77cfa3f6b17..d6d7049fb61 100644 --- a/clippy_lints/src/ptr_eq.rs +++ b/clippy_lints/src/ptr_eq.rs @@ -8,16 +8,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Use `std::ptr::eq` when applicable + /// ### What it does + /// Use `std::ptr::eq` when applicable /// - /// **Why is this bad?** `ptr::eq` can be used to compare `&T` references + /// ### Why is this bad? + /// `ptr::eq` can be used to compare `&T` references /// (which coerce to `*const T` implicitly) by their address rather than /// comparing the values they point to. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let a = &[1, 2, 3]; /// let b = &[1, 2, 3]; diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index afb198f4955..f1975056ddc 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -8,15 +8,15 @@ use rustc_span::sym; use std::fmt; declare_clippy_lint! { - /// **What it does:** Checks for usage of the `offset` pointer method with a `usize` casted to an + /// ### What it does + /// Checks for usage of the `offset` pointer method with a `usize` casted to an /// `isize`. /// - /// **Why is this bad?** If we’re always increasing the pointer address, we can avoid the numeric + /// ### Why is this bad? + /// If we’re always increasing the pointer address, we can avoid the numeric /// cast by using the `add` method instead. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// let vec = vec![b'a', b'b', b'c']; /// let ptr = vec.as_ptr(); diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index d66bac52243..0e682c692c7 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -13,13 +13,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for expressions that could be replaced by the question mark operator. + /// ### What it does + /// Checks for expressions that could be replaced by the question mark operator. /// - /// **Why is this bad?** Question mark usage is more idiomatic. + /// ### Why is this bad? + /// Question mark usage is more idiomatic. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```ignore /// if option.is_none() { /// return None; diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index b41c478c266..0179bd48ee3 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -18,14 +18,14 @@ use rustc_span::symbol::Ident; use std::cmp::Ordering; declare_clippy_lint! { - /// **What it does:** Checks for zipping a collection with the range of + /// ### What it does + /// Checks for zipping a collection with the range of /// `0.._.len()`. /// - /// **Why is this bad?** The code is better expressed with `.enumerate()`. + /// ### Why is this bad? + /// The code is better expressed with `.enumerate()`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let x = vec![1]; /// x.iter().zip(0..x.len()); @@ -41,13 +41,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for exclusive ranges where 1 is added to the + /// ### What it does + /// Checks for exclusive ranges where 1 is added to the /// upper bound, e.g., `x..(y+1)`. /// - /// **Why is this bad?** The code is more readable with an inclusive range + /// ### Why is this bad? + /// The code is more readable with an inclusive range /// like `x..=y`. /// - /// **Known problems:** Will add unnecessary pair of parentheses when the + /// ### Known problems + /// Will add unnecessary pair of parentheses when the /// expression is not wrapped in a pair but starts with a opening parenthesis /// and ends with a closing one. /// I.e., `let _ = (f()+1)..(f()+1)` results in `let _ = ((f()+1)..=f())`. @@ -61,7 +64,7 @@ declare_clippy_lint! { /// `RangeBounds` trait /// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)). /// - /// **Example:** + /// ### Example /// ```rust,ignore /// for x..(y+1) { .. } /// ``` @@ -75,18 +78,21 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for inclusive ranges where 1 is subtracted from + /// ### What it does + /// Checks for inclusive ranges where 1 is subtracted from /// the upper bound, e.g., `x..=(y-1)`. /// - /// **Why is this bad?** The code is more readable with an exclusive range + /// ### Why is this bad? + /// The code is more readable with an exclusive range /// like `x..y`. /// - /// **Known problems:** This will cause a warning that cannot be fixed if + /// ### Known problems + /// This will cause a warning that cannot be fixed if /// the consumer of the range only accepts a specific range type, instead of /// the generic `RangeBounds` trait /// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)). /// - /// **Example:** + /// ### Example /// ```rust,ignore /// for x..=(y-1) { .. } /// ``` @@ -100,16 +106,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for range expressions `x..y` where both `x` and `y` + /// ### What it does + /// Checks for range expressions `x..y` where both `x` and `y` /// are constant and `x` is greater or equal to `y`. /// - /// **Why is this bad?** Empty ranges yield no values so iterating them is a no-op. + /// ### Why is this bad? + /// Empty ranges yield no values so iterating them is a no-op. /// Moreover, trying to use a reversed range to index a slice will panic at run-time. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,no_run /// fn main() { /// (10..=0).for_each(|x| println!("{}", x)); @@ -133,16 +138,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for expressions like `x >= 3 && x < 8` that could + /// ### What it does + /// Checks for expressions like `x >= 3 && x < 8` that could /// be more readably expressed as `(3..8).contains(x)`. /// - /// **Why is this bad?** `contains` expresses the intent better and has less + /// ### Why is this bad? + /// `contains` expresses the intent better and has less /// failure modes (such as fencepost errors or using `||` instead of `&&`). /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // given /// let x = 6; diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 56ef95a88c8..530b3396abe 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -32,17 +32,18 @@ macro_rules! unwrap_or_continue { } declare_clippy_lint! { - /// **What it does:** Checks for a redundant `clone()` (and its relatives) which clones an owned + /// ### What it does + /// Checks for a redundant `clone()` (and its relatives) which clones an owned /// value that is going to be dropped without further use. /// - /// **Why is this bad?** It is not always possible for the compiler to eliminate useless + /// ### Why is this bad? + /// It is not always possible for the compiler to eliminate useless /// allocations and deallocations generated by redundant `clone()`s. /// - /// **Known problems:** - /// + /// ### Known problems /// False-negatives: analysis performed by this lint is conservative and limited. /// - /// **Example:** + /// ### Example /// ```rust /// # use std::path::Path; /// # #[derive(Clone)] diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 8f56a21ac5b..a79b2fe76e2 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -14,15 +14,15 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Detects closures called in the same expression where they + /// ### What it does + /// Detects closures called in the same expression where they /// are defined. /// - /// **Why is this bad?** It is unnecessarily adding to the expression's + /// ### Why is this bad? + /// It is unnecessarily adding to the expression's /// complexity. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// let a = (|| 42)() diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 061526c6f09..68b256d2944 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -6,14 +6,16 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `else` blocks that can be removed without changing semantics. + /// ### What it does + /// Checks for `else` blocks that can be removed without changing semantics. /// - /// **Why is this bad?** The `else` block adds unnecessary indentation and verbosity. + /// ### Why is this bad? + /// The `else` block adds unnecessary indentation and verbosity. /// - /// **Known problems:** Some may prefer to keep the `else` block for clarity. - /// - /// **Example:** + /// ### Known problems + /// Some may prefer to keep the `else` block for clarity. /// + /// ### Example /// ```rust /// fn my_func(count: u32) { /// if count == 0 { diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index d5ee8d3468d..47df4917510 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -8,15 +8,15 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for fields in struct literals where shorthands + /// ### What it does + /// Checks for fields in struct literals where shorthands /// could be used. /// - /// **Why is this bad?** If the field and variable names are the same, + /// ### Why is this bad? + /// If the field and variable names are the same, /// the field name is redundant. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let bar: u8 = 123; /// diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 05f9e01acb4..59a55b9dffa 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -5,16 +5,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for items declared `pub(crate)` that are not crate visible because they + /// ### What it does + /// Checks for items declared `pub(crate)` that are not crate visible because they /// are inside a private module. /// - /// **Why is this bad?** Writing `pub(crate)` is misleading when it's redundant due to the parent + /// ### Why is this bad? + /// Writing `pub(crate)` is misleading when it's redundant due to the parent /// module's visibility. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// mod internal { /// pub(crate) fn internal_fn() { } diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 9c6cd7b4fa6..290348c4509 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -10,17 +10,19 @@ use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for redundant slicing expressions which use the full range, and + /// ### What it does + /// Checks for redundant slicing expressions which use the full range, and /// do not change the type. /// - /// **Why is this bad?** It unnecessarily adds complexity to the expression. + /// ### Why is this bad? + /// It unnecessarily adds complexity to the expression. /// - /// **Known problems:** If the type being sliced has an implementation of `Index` + /// ### Known problems + /// If the type being sliced has an implementation of `Index` /// that actually changes anything then it can't be removed. However, this would be surprising /// to people reading the code and should have a note with it. /// - /// **Example:** - /// + /// ### Example /// ```ignore /// fn get_slice(x: &[u32]) -> &[u32] { /// &x[..] diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 48107d9c037..d5a1a61da6b 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -8,14 +8,14 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; declare_clippy_lint! { - /// **What it does:** Checks for constants and statics with an explicit `'static` lifetime. + /// ### What it does + /// Checks for constants and statics with an explicit `'static` lifetime. /// - /// **Why is this bad?** Adding `'static` to every reference can create very + /// ### Why is this bad? + /// Adding `'static` to every reference can create very /// complicated types. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// const FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] = /// &[...] diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index 0cf4e0ce7fe..65ab6cac442 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -9,16 +9,18 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** Checks for usage of `&Option<&T>`. + /// ### What it does + /// Checks for usage of `&Option<&T>`. /// - /// **Why is this bad?** Since `&` is Copy, it's useless to have a + /// ### Why is this bad? + /// Since `&` is Copy, it's useless to have a /// reference on `Option<&T>`. /// - /// **Known problems:** It may be irrelevant to use this lint on + /// ### Known problems + /// It may be irrelevant to use this lint on /// public API code as it will make a breaking change to apply it. /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// let x: &Option<&u32> = &Some(&0u32); /// ``` diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index d6336389b0a..e0930d69ab9 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -10,15 +10,18 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::BytePos; declare_clippy_lint! { - /// **What it does:** Checks for usage of `*&` and `*&mut` in expressions. + /// ### What it does + /// Checks for usage of `*&` and `*&mut` in expressions. /// - /// **Why is this bad?** Immediately dereferencing a reference is no-op and + /// ### Why is this bad? + /// Immediately dereferencing a reference is no-op and /// makes the code less clear. /// - /// **Known problems:** Multiple dereference/addrof pairs are not handled so + /// ### Known problems + /// Multiple dereference/addrof pairs are not handled so /// the suggested fix for `x = **&&y` is `x = *&y`, which is still incorrect. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// let a = f(*&mut b); @@ -101,13 +104,15 @@ impl EarlyLintPass for DerefAddrOf { } declare_clippy_lint! { - /// **What it does:** Checks for references in expressions that use + /// ### What it does + /// Checks for references in expressions that use /// auto dereference. /// - /// **Why is this bad?** The reference is a no-op and is automatically + /// ### Why is this bad? + /// The reference is a no-op and is automatically /// dereferenced by the compiler and makes the code less clear. /// - /// **Example:** + /// ### Example /// ```rust /// struct Point(u32, u32); /// let point = Point(30, 20); diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 75151167454..eab09733730 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -11,15 +11,15 @@ use rustc_span::source_map::{BytePos, Span}; use std::convert::TryFrom; declare_clippy_lint! { - /// **What it does:** Checks [regex](https://crates.io/crates/regex) creation + /// ### What it does + /// Checks [regex](https://crates.io/crates/regex) creation /// (with `Regex::new`, `RegexBuilder::new`, or `RegexSet::new`) for correct /// regex syntax. /// - /// **Why is this bad?** This will lead to a runtime panic. + /// ### Why is this bad? + /// This will lead to a runtime panic. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// Regex::new("|") /// ``` @@ -29,18 +29,21 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for trivial [regex](https://crates.io/crates/regex) + /// ### What it does + /// Checks for trivial [regex](https://crates.io/crates/regex) /// creation (with `Regex::new`, `RegexBuilder::new`, or `RegexSet::new`). /// - /// **Why is this bad?** Matching the regex can likely be replaced by `==` or + /// ### Why is this bad? + /// Matching the regex can likely be replaced by `==` or /// `str::starts_with`, `str::ends_with` or `std::contains` or other `str` /// methods. /// - /// **Known problems:** If the same regex is going to be applied to multiple + /// ### Known problems + /// If the same regex is going to be applied to multiple /// inputs, the precomputations done by `Regex` construction can give /// significantly better performance than any of the `str`-based methods. /// - /// **Example:** + /// ### Example /// ```ignore /// Regex::new("^foobar") /// ``` diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs index 17cb96bc4eb..54b9c8b3275 100644 --- a/clippy_lints/src/repeat_once.rs +++ b/clippy_lints/src/repeat_once.rs @@ -11,7 +11,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for usage of `.repeat(1)` and suggest the following method for each types. + /// ### What it does + /// Checks for usage of `.repeat(1)` and suggest the following method for each types. /// - `.to_string()` for `str` /// - `.clone()` for `String` /// - `.to_vec()` for `slice` @@ -19,13 +20,11 @@ declare_clippy_lint! { /// The lint will evaluate constant expressions and values as arguments of `.repeat(..)` and emit a message if /// they are equivalent to `1`. (Related discussion in [rust-clippy#7306](https://github.com/rust-lang/rust-clippy/issues/7306)) /// - /// **Why is this bad?** For example, `String.repeat(1)` is equivalent to `.clone()`. If cloning + /// ### Why is this bad? + /// For example, `String.repeat(1)` is equivalent to `.clone()`. If cloning /// the string is the intention behind this, `clone()` should be used. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// fn main() { /// let x = String::from("hello world").repeat(1); diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 251d527c265..db4b1002ce1 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -15,15 +15,15 @@ use rustc_span::source_map::Span; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for `let`-bindings, which are subsequently + /// ### What it does + /// Checks for `let`-bindings, which are subsequently /// returned. /// - /// **Why is this bad?** It is just extraneous code. Remove it to make your code + /// ### Why is this bad? + /// It is just extraneous code. Remove it to make your code /// more rusty. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn foo() -> String { /// let x = String::new(); @@ -42,14 +42,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for return statements at the end of a block. + /// ### What it does + /// Checks for return statements at the end of a block. /// - /// **Why is this bad?** Removing the `return` and semicolon will make the code + /// ### Why is this bad? + /// Removing the `return` and semicolon will make the code /// more rusty. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn foo(x: usize) -> usize { /// return x; diff --git a/clippy_lints/src/self_assignment.rs b/clippy_lints/src/self_assignment.rs index e7925c4fbde..fbd65fef7d1 100644 --- a/clippy_lints/src/self_assignment.rs +++ b/clippy_lints/src/self_assignment.rs @@ -6,16 +6,18 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for explicit self-assignments. + /// ### What it does + /// Checks for explicit self-assignments. /// - /// **Why is this bad?** Self-assignments are redundant and unlikely to be + /// ### Why is this bad? + /// Self-assignments are redundant and unlikely to be /// intentional. /// - /// **Known problems:** If expression contains any deref coercions or + /// ### Known problems + /// If expression contains any deref coercions or /// indexing operations they are assumed not to have any side effects. /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct Event { /// id: usize, diff --git a/clippy_lints/src/self_named_constructor.rs b/clippy_lints/src/self_named_constructor.rs index da991e1d90c..2123a14cc1b 100644 --- a/clippy_lints/src/self_named_constructor.rs +++ b/clippy_lints/src/self_named_constructor.rs @@ -6,14 +6,13 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Warns when constructors have the same name as their types. + /// ### What it does + /// Warns when constructors have the same name as their types. /// - /// **Why is this bad?** Repeating the name of the type is redundant. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Repeating the name of the type is redundant. /// + /// ### Example /// ```rust,ignore /// struct Foo {} /// diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index da3e30af35c..6966230156c 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -9,16 +9,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Looks for blocks of expressions and fires if the last expression returns + /// ### What it does + /// Looks for blocks of expressions and fires if the last expression returns /// `()` but is not followed by a semicolon. /// - /// **Why is this bad?** The semicolon might be optional but when extending the block with new + /// ### Why is this bad? + /// The semicolon might be optional but when extending the block with new /// code, it doesn't require a change in previous last line. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// fn main() { /// println!("Hello world") diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 169f7d26285..2cd0f85999c 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -5,14 +5,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for mis-uses of the serde API. + /// ### What it does + /// Checks for mis-uses of the serde API. /// - /// **Why is this bad?** Serde is very finnicky about how its API should be + /// ### Why is this bad? + /// Serde is very finnicky about how its API should be /// used, but the type system can't be used to enforce it (yet?). /// - /// **Known problems:** None. - /// - /// **Example:** Implementing `Visitor::visit_string` but not + /// ### Example + /// Implementing `Visitor::visit_string` but not /// `Visitor::visit_str`. pub SERDE_API_MISUSE, correctness, diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index ac3f7ebd14b..b28a37cabd4 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -14,17 +14,20 @@ use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; declare_clippy_lint! { - /// **What it does:** Checks for bindings that shadow other bindings already in + /// ### What it does + /// Checks for bindings that shadow other bindings already in /// scope, while just changing reference level or mutability. /// - /// **Why is this bad?** Not much, in fact it's a very common pattern in Rust + /// ### Why is this bad? + /// Not much, in fact it's a very common pattern in Rust /// code. Still, some may opt to avoid it in their code base, they can set this /// lint to `Warn`. /// - /// **Known problems:** This lint, as the other shadowing related lints, + /// ### Known problems + /// This lint, as the other shadowing related lints, /// currently only catches very simple patterns. /// - /// **Example:** + /// ### Example /// ```rust /// # let x = 1; /// // Bad @@ -39,18 +42,21 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for bindings that shadow other bindings already in + /// ### What it does + /// Checks for bindings that shadow other bindings already in /// scope, while reusing the original value. /// - /// **Why is this bad?** Not too much, in fact it's a common pattern in Rust + /// ### Why is this bad? + /// Not too much, in fact it's a common pattern in Rust /// code. Still, some argue that name shadowing like this hurts readability, /// because a value may be bound to different things depending on position in /// the code. /// - /// **Known problems:** This lint, as the other shadowing related lints, + /// ### Known problems + /// This lint, as the other shadowing related lints, /// currently only catches very simple patterns. /// - /// **Example:** + /// ### Example /// ```rust /// let x = 2; /// let x = x + 1; @@ -66,21 +72,24 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for bindings that shadow other bindings already in + /// ### What it does + /// Checks for bindings that shadow other bindings already in /// scope, either without a initialization or with one that does not even use /// the original value. /// - /// **Why is this bad?** Name shadowing can hurt readability, especially in + /// ### Why is this bad? + /// Name shadowing can hurt readability, especially in /// large code bases, because it is easy to lose track of the active binding at /// any place in the code. This can be alleviated by either giving more specific /// names to bindings or introducing more scopes to contain the bindings. /// - /// **Known problems:** This lint, as the other shadowing related lints, + /// ### Known problems + /// This lint, as the other shadowing related lints, /// currently only catches very simple patterns. Note that /// `allow`/`warn`/`deny`/`forbid` attributes only work on the function level /// for this lint. /// - /// **Example:** + /// ### Example /// ```rust /// # let y = 1; /// # let z = 2; diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 1eaad438237..f6487b8c46b 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -7,15 +7,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{edition::Edition, symbol::kw, Span, Symbol}; declare_clippy_lint! { - /// **What it does:** Checking for imports with single component use path. + /// ### What it does + /// Checking for imports with single component use path. /// - /// **Why is this bad?** Import with single component use path such as `use cratename;` + /// ### Why is this bad? + /// Import with single component use path such as `use cratename;` /// is not necessary, and thus should be removed. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// use regex; /// diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index b1965cfd601..3e4e4a8d0c0 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -11,16 +11,16 @@ use rustc_middle::ty::{self, Ty, TyS, TypeAndMut}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Detects expressions where + /// ### What it does + /// Detects expressions where /// `size_of::` or `size_of_val::` is used as a /// count of elements of type `T` /// - /// **Why is this bad?** These functions expect a count + /// ### Why is this bad? + /// These functions expect a count /// of `T` and not a number of bytes /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,no_run /// # use std::ptr::copy_nonoverlapping; /// # use std::mem::size_of; diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index e5c58d70b60..3d039e13065 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -13,14 +13,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** Checks slow zero-filled vector initialization + /// ### What it does + /// Checks slow zero-filled vector initialization /// - /// **Why is this bad?** These structures are non-idiomatic and less efficient than simply using + /// ### Why is this bad? + /// These structures are non-idiomatic and less efficient than simply using /// `vec![0; len]`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use core::iter::repeat; /// # let len = 4; diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 65790375c73..4ea1293d504 100644 --- a/clippy_lints/src/stable_sort_primitive.rs +++ b/clippy_lints/src/stable_sort_primitive.rs @@ -7,22 +7,18 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// When sorting primitive values (integers, bools, chars, as well /// as arrays, slices, and tuples of such items), it is better to /// use an unstable sort than a stable sort. /// - /// **Why is this bad?** + /// ### Why is this bad? /// Using a stable sort consumes more memory and cpu cycles. Because /// values which compare equal are identical, preserving their /// relative order (the guarantee that a stable sort provides) means /// nothing, while the extra costs still apply. /// - /// **Known problems:** - /// None - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let mut vec = vec![2, 1, 3]; /// vec.sort(); diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 958e462125e..1a78a4968e5 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -14,16 +14,15 @@ use rustc_span::source_map::Spanned; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for string appends of the form `x = x + y` (without + /// ### What it does + /// Checks for string appends of the form `x = x + y` (without /// `let`!). /// - /// **Why is this bad?** It's not really bad, but some people think that the + /// ### Why is this bad? + /// It's not really bad, but some people think that the /// `.push_str(_)` method is more readable. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let mut x = "Hello".to_owned(); /// x = x + ", World"; @@ -38,11 +37,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for all instances of `x + _` where `x` is of type + /// ### What it does + /// Checks for all instances of `x + _` where `x` is of type /// `String`, but only if [`string_add_assign`](#string_add_assign) does *not* /// match. /// - /// **Why is this bad?** It's not bad in and of itself. However, this particular + /// ### Why is this bad? + /// It's not bad in and of itself. However, this particular /// `Add` implementation is asymmetric (the other operand need not be `String`, /// but `x` does), while addition as mathematically defined is symmetric, also /// the `String::push_str(_)` function is a perfectly good replacement. @@ -52,10 +53,7 @@ declare_clippy_lint! { /// in other languages is actually fine, which is why we decided to make this /// particular lint `allow` by default. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let x = "Hello".to_owned(); /// x + ", World"; @@ -66,13 +64,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for the `as_bytes` method called on string literals + /// ### What it does + /// Checks for the `as_bytes` method called on string literals /// that contain only ASCII characters. /// - /// **Why is this bad?** Byte string literals (e.g., `b"foo"`) can be used + /// ### Why is this bad? + /// Byte string literals (e.g., `b"foo"`) can be used /// instead. They are shorter but less discoverable than `as_bytes()`. /// - /// **Known Problems:** + /// ### Known problems /// `"str".as_bytes()` and the suggested replacement of `b"str"` are not /// equivalent because they have different types. The former is `&[u8]` /// while the latter is `&[u8; 3]`. That means in general they will have a @@ -94,7 +94,7 @@ declare_clippy_lint! { /// `b"str"` but `&b"str"[..]`, which is a great deal of punctuation and not /// more readable than a function call. /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let bs = "a byte string".as_bytes(); @@ -177,13 +177,13 @@ fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { } declare_clippy_lint! { - /// **What it does:** Check if the string is transformed to byte array and casted back to string. + /// ### What it does + /// Check if the string is transformed to byte array and casted back to string. /// - /// **Why is this bad?** It's unnecessary, the string can be used directly. + /// ### Why is this bad? + /// It's unnecessary, the string can be used directly. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]).unwrap(); /// ``` @@ -317,16 +317,15 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { } declare_clippy_lint! { - /// **What it does:** This lint checks for `.to_string()` method calls on values of type `&str`. + /// ### What it does + /// This lint checks for `.to_string()` method calls on values of type `&str`. /// - /// **Why is this bad?** The `to_string` method is also used on other types to convert them to a string. + /// ### Why is this bad? + /// The `to_string` method is also used on other types to convert them to a string. /// When called on a `&str` it turns the `&str` into the owned variant `String`, which can be better /// expressed with `.to_owned()`. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // example code where clippy issues a warning /// let _ = "str".to_string(); @@ -366,14 +365,14 @@ impl LateLintPass<'_> for StrToString { } declare_clippy_lint! { - /// **What it does:** This lint checks for `.to_string()` method calls on values of type `String`. + /// ### What it does + /// This lint checks for `.to_string()` method calls on values of type `String`. /// - /// **Why is this bad?** The `to_string` method is also used on other types to convert them to a string. + /// ### Why is this bad? + /// The `to_string` method is also used on other types to convert them to a string. /// When called on a `String` it only clones the `String`, which can be better expressed with `.clone()`. - /// **Known problems:** None. - /// - /// **Example:** /// + /// ### Example /// ```rust /// // example code where clippy issues a warning /// let msg = String::from("Hello World"); diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index 2ccf3a3796d..516fa3d95b4 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -11,16 +11,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::{sym, Symbol}; declare_clippy_lint! { - /// **What it does:** Checks for usage of `libc::strlen` on a `CString` or `CStr` value, + /// ### What it does + /// Checks for usage of `libc::strlen` on a `CString` or `CStr` value, /// and suggest calling `as_bytes().len()` or `to_bytes().len()` respectively instead. /// - /// **Why is this bad?** This avoids calling an unsafe `libc` function. + /// ### Why is this bad? + /// This avoids calling an unsafe `libc` function. /// Currently, it also avoids calculating the length. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust, ignore /// use std::ffi::CString; /// let cstring = CString::new("foo").expect("CString::new failed"); diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index bb707f78fcc..a8e962d1af3 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -13,20 +13,21 @@ use rustc_span::symbol::Ident; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Checks for unlikely usages of binary operators that are almost /// certainly typos and/or copy/paste errors, given the other usages /// of binary operators nearby. - /// **Why is this bad?** + /// + /// ### Why is this bad? /// They are probably bugs and if they aren't then they look like bugs /// and you should add a comment explaining why you are doing such an /// odd set of operations. - /// **Known problems:** + /// + /// ### Known problems /// There may be some false positives if you are trying to do something /// unusual that happens to look like a typo. /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct Vec3 { /// x: f64, diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index f2bffd55321..682fad00a13 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -8,14 +8,14 @@ use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Lints for suspicious operations in impls of arithmetic operators, e.g. + /// ### What it does + /// Lints for suspicious operations in impls of arithmetic operators, e.g. /// subtracting elements in an Add impl. /// - /// **Why this is bad?** This is probably a typo or copy-and-paste error and not intended. + /// ### Why is this bad? + /// This is probably a typo or copy-and-paste error and not intended. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```ignore /// impl Add for Foo { /// type Output = Foo; @@ -31,14 +31,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Lints for suspicious operations in impls of OpAssign, e.g. + /// ### What it does + /// Lints for suspicious operations in impls of OpAssign, e.g. /// subtracting elements in an AddAssign impl. /// - /// **Why this is bad?** This is probably a typo or copy-and-paste error and not intended. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This is probably a typo or copy-and-paste error and not intended. /// - /// **Example:** + /// ### Example /// ```ignore /// impl AddAssign for Foo { /// fn add_assign(&mut self, other: Foo) { diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 19967e2c970..4fa8e77a67b 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -12,14 +12,14 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for manual swapping. + /// ### What it does + /// Checks for manual swapping. /// - /// **Why is this bad?** The `std::mem::swap` function exposes the intent better + /// ### Why is this bad? + /// The `std::mem::swap` function exposes the intent better /// without deinitializing or copying either variable. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let mut a = 42; /// let mut b = 1337; @@ -40,13 +40,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `foo = bar; bar = foo` sequences. - /// - /// **Why is this bad?** This looks like a failed attempt to swap. + /// ### What it does + /// Checks for `foo = bar; bar = foo` sequences. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This looks like a failed attempt to swap. /// - /// **Example:** + /// ### Example /// ```rust /// # let mut a = 1; /// # let mut b = 2; diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index e2c144709f5..6a73b94d87e 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -7,16 +7,16 @@ use rustc_span::source_map::{BytePos, Span}; use std::convert::TryFrom; declare_clippy_lint! { - /// **What it does:** Checks doc comments for usage of tab characters. + /// ### What it does + /// Checks doc comments for usage of tab characters. /// - /// **Why is this bad?** The rust style-guide promotes spaces instead of tabs for indentation. + /// ### Why is this bad? + /// The rust style-guide promotes spaces instead of tabs for indentation. /// To keep a consistent view on the source, also doc comments should not have tabs. /// Also, explaining ascii-diagrams containing tabs can get displayed incorrectly when the /// display settings of the author and reader differ. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// /// /// /// Struct to hold two strings: diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index 8ef25dc816c..a9da690339c 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -5,15 +5,15 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for construction of a structure or tuple just to + /// ### What it does + /// Checks for construction of a structure or tuple just to /// assign a value in it. /// - /// **Why is this bad?** Readability. If the structure is only created to be + /// ### Why is this bad? + /// Readability. If the structure is only created to be /// updated, why not write the structure you want in the first place? /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// (0, 0).0 = 1 /// ``` diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index c66a596c784..1c14a919995 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -9,12 +9,14 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `.to_digit(..).is_some()` on `char`s. + /// ### What it does + /// Checks for `.to_digit(..).is_some()` on `char`s. /// - /// **Why is this bad?** This is a convoluted way of checking if a `char` is a digit. It's + /// ### Why is this bad? + /// This is a convoluted way of checking if a `char` is a digit. It's /// more straight forward to use the dedicated `is_digit` method. /// - /// **Example:** + /// ### Example /// ```rust /// # let c = 'c'; /// # let radix = 10; diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index 4fb297ac6c6..b036ed9a3d2 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -7,15 +7,15 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** Checks for uses of `to_string()` in `Display` traits. + /// ### What it does + /// Checks for uses of `to_string()` in `Display` traits. /// - /// **Why is this bad?** Usually `to_string` is implemented indirectly + /// ### Why is this bad? + /// Usually `to_string` is implemented indirectly /// via `Display`. Hence using it while implementing `Display` would /// lead to infinite recursion. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// ```rust /// use std::fmt; diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 74a94db1800..79367c4230c 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -11,14 +11,14 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** This lint warns about unnecessary type repetitions in trait bounds + /// ### What it does + /// This lint warns about unnecessary type repetitions in trait bounds /// - /// **Why is this bad?** Repeating the type for every bound makes the code + /// ### Why is this bad? + /// Repeating the type for every bound makes the code /// less readable than combining the bounds /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// pub fn foo(t: T) where T: Copy, T: Clone {} /// ``` @@ -34,15 +34,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for cases where generics are being used and multiple + /// ### What it does + /// Checks for cases where generics are being used and multiple /// syntax specifications for trait bounds are used simultaneously. /// - /// **Why is this bad?** Duplicate bounds makes the code + /// ### Why is this bad? + /// Duplicate bounds makes the code /// less readable than specifing them only once. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn func(arg: T) where T: Clone + Default {} /// ``` diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 89fd5faa165..33ec9c331ce 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -20,15 +20,18 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** Checks for transmutes that can't ever be correct on any + /// ### What it does + /// Checks for transmutes that can't ever be correct on any /// architecture. /// - /// **Why is this bad?** It's basically guaranteed to be undefined behaviour. + /// ### Why is this bad? + /// It's basically guaranteed to be undefined behaviour. /// - /// **Known problems:** When accessing C, users might want to store pointer + /// ### Known problems + /// When accessing C, users might want to store pointer /// sized objects in `extradata` arguments to save an allocation. /// - /// **Example:** + /// ### Example /// ```ignore /// let ptr: *const T = core::intrinsics::transmute('x') /// ``` @@ -39,15 +42,15 @@ declare_clippy_lint! { // FIXME: Move this to `complexity` again, after #5343 is fixed declare_clippy_lint! { - /// **What it does:** Checks for transmutes to the original type of the object + /// ### What it does + /// Checks for transmutes to the original type of the object /// and transmutes that could be a cast. /// - /// **Why is this bad?** Readability. The code tricks people into thinking that + /// ### Why is this bad? + /// Readability. The code tricks people into thinking that /// something complex is going on. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// core::intrinsics::transmute(t); // where the result type is the same as `t`'s /// ``` @@ -58,14 +61,14 @@ declare_clippy_lint! { // FIXME: Merge this lint with USELESS_TRANSMUTE once that is out of the nursery. declare_clippy_lint! { - /// **What it does:**Checks for transmutes that could be a pointer cast. + /// ### What it does + ///Checks for transmutes that could be a pointer cast. /// - /// **Why is this bad?** Readability. The code tricks people into thinking that + /// ### Why is this bad? + /// Readability. The code tricks people into thinking that /// something complex is going on. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// /// ```rust /// # let p: *const [i32] = &[]; @@ -82,14 +85,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes between a type `T` and `*T`. + /// ### What it does + /// Checks for transmutes between a type `T` and `*T`. /// - /// **Why is this bad?** It's easy to mistakenly transmute between a type and a + /// ### Why is this bad? + /// It's easy to mistakenly transmute between a type and a /// pointer to that type. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// core::intrinsics::transmute(t) // where the result type is the same as /// // `*t` or `&t`'s @@ -100,17 +103,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a pointer to a reference. + /// ### What it does + /// Checks for transmutes from a pointer to a reference. /// - /// **Why is this bad?** This can always be rewritten with `&` and `*`. + /// ### Why is this bad? + /// This can always be rewritten with `&` and `*`. /// - /// **Known problems:** + /// ### Known problems /// - `mem::transmute` in statics and constants is stable from Rust 1.46.0, /// while dereferencing raw pointer is not stable yet. /// If you need to do this in those places, /// you would have to use `transmute` instead. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// unsafe { /// let _: &T = std::mem::transmute(p); // where p: *const T @@ -125,11 +130,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes from an integer to a `char`. + /// ### What it does + /// Checks for transmutes from an integer to a `char`. /// - /// **Why is this bad?** Not every integer is a Unicode scalar value. + /// ### Why is this bad? + /// Not every integer is a Unicode scalar value. /// - /// **Known problems:** + /// ### Known problems /// - [`from_u32`] which this lint suggests using is slower than `transmute` /// as it needs to validate the input. /// If you are certain that the input is always a valid Unicode scalar value, @@ -140,7 +147,7 @@ declare_clippy_lint! { /// [`from_u32`]: https://doc.rust-lang.org/std/char/fn.from_u32.html /// [`from_u32_unchecked`]: https://doc.rust-lang.org/std/char/fn.from_u32_unchecked.html /// - /// **Example:** + /// ### Example /// ```rust /// let x = 1_u32; /// unsafe { @@ -156,11 +163,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a `&[u8]` to a `&str`. + /// ### What it does + /// Checks for transmutes from a `&[u8]` to a `&str`. /// - /// **Why is this bad?** Not every byte slice is a valid UTF-8 string. + /// ### Why is this bad? + /// Not every byte slice is a valid UTF-8 string. /// - /// **Known problems:** + /// ### Known problems /// - [`from_utf8`] which this lint suggests using is slower than `transmute` /// as it needs to validate the input. /// If you are certain that the input is always a valid UTF-8, @@ -171,7 +180,7 @@ declare_clippy_lint! { /// [`from_utf8`]: https://doc.rust-lang.org/std/str/fn.from_utf8.html /// [`from_utf8_unchecked`]: https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.html /// - /// **Example:** + /// ### Example /// ```rust /// let b: &[u8] = &[1_u8, 2_u8]; /// unsafe { @@ -187,13 +196,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes from an integer to a `bool`. - /// - /// **Why is this bad?** This might result in an invalid in-memory representation of a `bool`. + /// ### What it does + /// Checks for transmutes from an integer to a `bool`. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This might result in an invalid in-memory representation of a `bool`. /// - /// **Example:** + /// ### Example /// ```rust /// let x = 1_u8; /// unsafe { @@ -209,14 +218,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes from an integer to a float. + /// ### What it does + /// Checks for transmutes from an integer to a float. /// - /// **Why is this bad?** Transmutes are dangerous and error-prone, whereas `from_bits` is intuitive + /// ### Why is this bad? + /// Transmutes are dangerous and error-prone, whereas `from_bits` is intuitive /// and safe. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// unsafe { /// let _: f32 = std::mem::transmute(1_u32); // where x: u32 @@ -231,14 +240,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a float to an integer. + /// ### What it does + /// Checks for transmutes from a float to an integer. /// - /// **Why is this bad?** Transmutes are dangerous and error-prone, whereas `to_bits` is intuitive + /// ### Why is this bad? + /// Transmutes are dangerous and error-prone, whereas `to_bits` is intuitive /// and safe. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// unsafe { /// let _: u32 = std::mem::transmute(1f32); @@ -253,15 +262,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a pointer to a pointer, or + /// ### What it does + /// Checks for transmutes from a pointer to a pointer, or /// from a reference to a reference. /// - /// **Why is this bad?** Transmutes are dangerous, and these can instead be + /// ### Why is this bad? + /// Transmutes are dangerous, and these can instead be /// written as casts. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let ptr = &1u32 as *const u32; /// unsafe { @@ -280,15 +289,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for transmutes between collections whose + /// ### What it does + /// Checks for transmutes between collections whose /// types have different ABI, size or alignment. /// - /// **Why is this bad?** This is undefined behavior. + /// ### Why is this bad? + /// This is undefined behavior. /// - /// **Known problems:** Currently, we cannot know whether a type is a + /// ### Known problems + /// Currently, we cannot know whether a type is a /// collection, so we just lint the ones that come with `std`. /// - /// **Example:** + /// ### Example /// ```rust /// // different size, therefore likely out-of-bounds memory access /// // You absolutely do not want this in your code! diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 0c39d4d8cf4..a67fa792205 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -10,15 +10,18 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; declare_clippy_lint! { - /// **What it does:** Checks for transmute calls which would receive a null pointer. + /// ### What it does + /// Checks for transmute calls which would receive a null pointer. /// - /// **Why is this bad?** Transmuting a null pointer is undefined behavior. + /// ### Why is this bad? + /// Transmuting a null pointer is undefined behavior. /// - /// **Known problems:** Not all cases can be detected at the moment of this writing. + /// ### Known problems + /// Not all cases can be detected at the moment of this writing. /// For example, variables which hold a null pointer and are then fed to a `transmute` /// call, aren't detectable yet. /// - /// **Example:** + /// ### Example /// ```rust /// let null_ref: &u64 = unsafe { std::mem::transmute(0 as *const u64) }; /// ``` diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index f2ba2b2ecf6..1196271d5dd 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -13,16 +13,16 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for usages of `Err(x)?`. + /// ### What it does + /// Checks for usages of `Err(x)?`. /// - /// **Why is this bad?** The `?` operator is designed to allow calls that + /// ### Why is this bad? + /// The `?` operator is designed to allow calls that /// can fail to be easily chained. For example, `foo()?.bar()` or /// `foo(bar()?)`. Because `Err(x)?` can't be used that way (it will /// always return), it is more clear to write `return Err(x)`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn foo(fail: bool) -> Result { /// if fail { diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 7d629b5455b..ad7409fe3a9 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -20,16 +20,16 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; declare_clippy_lint! { - /// **What it does:** Checks for use of `Box>` anywhere in the code. + /// ### What it does + /// Checks for use of `Box>` anywhere in the code. /// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information. /// - /// **Why is this bad?** `Vec` already keeps its contents in a separate area on + /// ### Why is this bad? + /// `Vec` already keeps its contents in a separate area on /// the heap. So if you `Box` it, you just add another level of indirection /// without any benefit whatsoever. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// struct X { /// values: Box>, @@ -49,16 +49,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of `Vec>` where T: Sized anywhere in the code. + /// ### What it does + /// Checks for use of `Vec>` where T: Sized anywhere in the code. /// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information. /// - /// **Why is this bad?** `Vec` already keeps its contents in a separate area on + /// ### Why is this bad? + /// `Vec` already keeps its contents in a separate area on /// the heap. So if you `Box` its contents, you just add another level of indirection. /// - /// **Known problems:** Vec> makes sense if T is a large type (see [#3530](https://github.com/rust-lang/rust-clippy/issues/3530), + /// ### Known problems + /// Vec> makes sense if T is a large type (see [#3530](https://github.com/rust-lang/rust-clippy/issues/3530), /// 1st comment). /// - /// **Example:** + /// ### Example /// ```rust /// struct X { /// values: Vec>, @@ -78,19 +81,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of `Option>` in function signatures and type + /// ### What it does + /// Checks for use of `Option>` in function signatures and type /// definitions /// - /// **Why is this bad?** `Option<_>` represents an optional value. `Option>` + /// ### Why is this bad? + /// `Option<_>` represents an optional value. `Option>` /// represents an optional optional value which is logically the same thing as an optional /// value but has an unneeded extra level of wrapping. /// /// If you have a case where `Some(Some(_))`, `Some(None)` and `None` are distinct cases, /// consider a custom `enum` instead, with clear names for each case. /// - /// **Known problems:** None. - /// - /// **Example** + /// ### Example /// ```rust /// fn get_data() -> Option> { /// None @@ -116,10 +119,12 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for usage of any `LinkedList`, suggesting to use a + /// ### What it does + /// Checks for usage of any `LinkedList`, suggesting to use a /// `Vec` or a `VecDeque` (formerly called `RingBuf`). /// - /// **Why is this bad?** Gankro says: + /// ### Why is this bad? + /// Gankro says: /// /// > The TL;DR of `LinkedList` is that it's built on a massive amount of /// pointers and indirection. @@ -138,10 +143,11 @@ declare_clippy_lint! { /// can still be better /// > because of how expensive it is to seek to the middle of a `LinkedList`. /// - /// **Known problems:** False positives – the instances where using a + /// ### Known problems + /// False positives – the instances where using a /// `LinkedList` makes sense are few and far between, but they can still happen. /// - /// **Example:** + /// ### Example /// ```rust /// # use std::collections::LinkedList; /// let x: LinkedList = LinkedList::new(); @@ -152,15 +158,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of `&Box` anywhere in the code. + /// ### What it does + /// Checks for use of `&Box` anywhere in the code. /// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information. /// - /// **Why is this bad?** Any `&Box` can also be a `&T`, which is more + /// ### Why is this bad? + /// Any `&Box` can also be a `&T`, which is more /// general. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// fn foo(bar: &Box) { ... } /// ``` @@ -176,14 +182,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of redundant allocations anywhere in the code. + /// ### What it does + /// Checks for use of redundant allocations anywhere in the code. /// - /// **Why is this bad?** Expressions such as `Rc<&T>`, `Rc>`, `Rc>`, `Rc>`, Arc<&T>`, `Arc>`, + /// ### Why is this bad? + /// Expressions such as `Rc<&T>`, `Rc>`, `Rc>`, `Rc>`, Arc<&T>`, `Arc>`, /// `Arc>`, `Arc>`, `Box<&T>`, `Box>`, `Box>`, `Box>`, add an unnecessary level of indirection. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use std::rc::Rc; /// fn foo(bar: Rc<&usize>) {} @@ -200,9 +206,11 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `Rc` and `Arc` when `T` is a mutable buffer type such as `String` or `Vec`. + /// ### What it does + /// Checks for `Rc` and `Arc` when `T` is a mutable buffer type such as `String` or `Vec`. /// - /// **Why is this bad?** Expressions such as `Rc` usually have no advantage over `Rc`, since + /// ### Why is this bad? + /// Expressions such as `Rc` usually have no advantage over `Rc`, since /// it is larger and involves an extra level of indirection, and doesn't implement `Borrow`. /// /// While mutating a buffer type would still be possible with `Rc::get_mut()`, it only @@ -211,10 +219,11 @@ declare_clippy_lint! { /// type with an interior mutable container (such as `RefCell` or `Mutex`) would normally /// be used. /// - /// **Known problems:** This pattern can be desirable to avoid the overhead of a `RefCell` or `Mutex` for + /// ### Known problems + /// This pattern can be desirable to avoid the overhead of a `RefCell` or `Mutex` for /// cases where mutation only happens before there are any additional references. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// # use std::rc::Rc; /// fn foo(interned: Rc) { ... } @@ -231,15 +240,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for types used in structs, parameters and `let` + /// ### What it does + /// Checks for types used in structs, parameters and `let` /// declarations above a certain complexity threshold. /// - /// **Why is this bad?** Too complex types make the code less readable. Consider + /// ### Why is this bad? + /// Too complex types make the code less readable. Consider /// using a `type` definition to simplify them. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use std::rc::Rc; /// struct Foo { @@ -252,16 +261,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for `Rc>`. + /// ### What it does + /// Checks for `Rc>`. /// - /// **Why is this bad?** `Rc` is used in single thread and `Mutex` is used in multi thread. + /// ### Why is this bad? + /// `Rc` is used in single thread and `Mutex` is used in multi thread. /// Consider using `Rc>` in single thread or `Arc>` in multi thread. /// - /// **Known problems:** Sometimes combining generic types can lead to the requirement that a + /// ### Known problems + /// Sometimes combining generic types can lead to the requirement that a /// type use Rc in conjunction with Mutex. We must consider those cases false positives, but /// alas they are quite hard to rule out. Luckily they are also rare. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// use std::rc::Rc; /// use std::sync::Mutex; diff --git a/clippy_lints/src/undropped_manually_drops.rs b/clippy_lints/src/undropped_manually_drops.rs index f4f5e1233e3..47571e608c7 100644 --- a/clippy_lints/src/undropped_manually_drops.rs +++ b/clippy_lints/src/undropped_manually_drops.rs @@ -6,15 +6,17 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Prevents the safe `std::mem::drop` function from being called on `std::mem::ManuallyDrop`. + /// ### What it does + /// Prevents the safe `std::mem::drop` function from being called on `std::mem::ManuallyDrop`. /// - /// **Why is this bad?** The safe `drop` function does not drop the inner value of a `ManuallyDrop`. + /// ### Why is this bad? + /// The safe `drop` function does not drop the inner value of a `ManuallyDrop`. /// - /// **Known problems:** Does not catch cases if the user binds `std::mem::drop` + /// ### Known problems + /// Does not catch cases if the user binds `std::mem::drop` /// to a different name and calls it that way. /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct S; /// drop(std::mem::ManuallyDrop::new(S)); diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index 2f0a61898ba..f337dec8f2b 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -10,14 +10,15 @@ use rustc_span::source_map::Span; use unicode_normalization::UnicodeNormalization; declare_clippy_lint! { - /// **What it does:** Checks for invisible Unicode characters in the code. + /// ### What it does + /// Checks for invisible Unicode characters in the code. /// - /// **Why is this bad?** Having an invisible character in the code makes for all + /// ### Why is this bad? + /// Having an invisible character in the code makes for all /// sorts of April fools, but otherwise is very much frowned upon. /// - /// **Known problems:** None. - /// - /// **Example:** You don't see it, but there may be a zero-width space or soft hyphen + /// ### Example + /// You don't see it, but there may be a zero-width space or soft hyphen /// some­where in this text. pub INVISIBLE_CHARACTERS, correctness, @@ -25,17 +26,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for non-ASCII characters in string literals. + /// ### What it does + /// Checks for non-ASCII characters in string literals. /// - /// **Why is this bad?** Yeah, we know, the 90's called and wanted their charset + /// ### Why is this bad? + /// Yeah, we know, the 90's called and wanted their charset /// back. Even so, there still are editors and other programs out there that /// don't work well with Unicode. So if the code is meant to be used /// internationally, on multiple operating systems, or has other portability /// requirements, activating this lint could be useful. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = String::from("€"); /// ``` @@ -49,16 +50,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for string literals that contain Unicode in a form + /// ### What it does + /// Checks for string literals that contain Unicode in a form /// that is not equal to its /// [NFC-recomposition](http://www.unicode.org/reports/tr15/#Norm_Forms). /// - /// **Why is this bad?** If such a string is compared to another, the results + /// ### Why is this bad? + /// If such a string is compared to another, the results /// may be surprising. /// - /// **Known problems** None. - /// - /// **Example:** You may not see it, but "à"" and "à"" aren't the same string. The + /// ### Example + /// You may not see it, but "à"" and "à"" aren't the same string. The /// former when escaped is actually `"a\u{300}"` while the latter is `"\u{e0}"`. pub UNICODE_NOT_NFC, pedantic, diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 1c420a50427..900d4531760 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -10,20 +10,22 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{BytePos, Span}; declare_clippy_lint! { - /// **What it does:** Checks for functions that expect closures of type + /// ### What it does + /// Checks for functions that expect closures of type /// Fn(...) -> Ord where the implemented closure returns the unit type. /// The lint also suggests to remove the semi-colon at the end of the statement if present. /// - /// **Why is this bad?** Likely, returning the unit type is unintentional, and + /// ### Why is this bad? + /// Likely, returning the unit type is unintentional, and /// could simply be caused by an extra semi-colon. Since () implements Ord /// it doesn't cause a compilation error. /// This is the same reasoning behind the unit_cmp lint. /// - /// **Known problems:** If returning unit is intentional, then there is no + /// ### Known problems + /// If returning unit is intentional, then there is no /// way of specifying this without triggering needless_return lint /// - /// **Example:** - /// + /// ### Example /// ```rust /// let mut twins = vec!((1, 1), (2, 2)); /// twins.sort_by_key(|x| { x.1; }); diff --git a/clippy_lints/src/unit_types/mod.rs b/clippy_lints/src/unit_types/mod.rs index 64420a03933..66b1abbe50b 100644 --- a/clippy_lints/src/unit_types/mod.rs +++ b/clippy_lints/src/unit_types/mod.rs @@ -8,14 +8,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for binding a unit value. + /// ### What it does + /// Checks for binding a unit value. /// - /// **Why is this bad?** A unit value cannot usefully be used anywhere. So + /// ### Why is this bad? + /// A unit value cannot usefully be used anywhere. So /// binding one is kind of pointless. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// let x = { /// 1; @@ -27,16 +27,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for comparisons to unit. This includes all binary + /// ### What it does + /// Checks for comparisons to unit. This includes all binary /// comparisons (like `==` and `<`) and asserts. /// - /// **Why is this bad?** Unit is always equal to itself, and thus is just a + /// ### Why is this bad? + /// Unit is always equal to itself, and thus is just a /// clumsily written constant. Mostly this happens when someone accidentally /// adds semicolons at the end of the operands. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # fn foo() {}; /// # fn bar() {}; @@ -74,14 +74,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for passing a unit value as an argument to a function without using a + /// ### What it does + /// Checks for passing a unit value as an argument to a function without using a /// unit literal (`()`). /// - /// **Why is this bad?** This is likely the result of an accidental semicolon. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// This is likely the result of an accidental semicolon. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// foo({ /// let a = bar(); diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 9cca05b1f1a..1eafdee0352 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -7,16 +7,15 @@ use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for comparisons with an address of a function item. + /// ### What it does + /// Checks for comparisons with an address of a function item. /// - /// **Why is this bad?** Function item address is not guaranteed to be unique and could vary + /// ### Why is this bad? + /// Function item address is not guaranteed to be unique and could vary /// between different code generation units. Furthermore different function items could have /// the same address after being merged together. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// type F = fn(); /// fn a() {} @@ -31,17 +30,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for comparisons with an address of a trait vtable. + /// ### What it does + /// Checks for comparisons with an address of a trait vtable. /// - /// **Why is this bad?** Comparing trait objects pointers compares an vtable addresses which + /// ### Why is this bad? + /// Comparing trait objects pointers compares an vtable addresses which /// are not guaranteed to be unique and could vary between different code generation units. /// Furthermore vtables for different types could have the same address after being merged /// together. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// let a: Rc = ... /// let b: Rc = ... diff --git a/clippy_lints/src/unnecessary_self_imports.rs b/clippy_lints/src/unnecessary_self_imports.rs index 48c54d79cf1..4cfd2df551f 100644 --- a/clippy_lints/src/unnecessary_self_imports.rs +++ b/clippy_lints/src/unnecessary_self_imports.rs @@ -7,16 +7,18 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::kw; declare_clippy_lint! { - /// **What it does:** Checks for imports ending in `::{self}`. + /// ### What it does + /// Checks for imports ending in `::{self}`. /// - /// **Why is this bad?** In most cases, this can be written much more cleanly by omitting `::{self}`. + /// ### Why is this bad? + /// In most cases, this can be written much more cleanly by omitting `::{self}`. /// - /// **Known problems:** Removing `::{self}` will cause any non-module items at the same path to also be imported. + /// ### Known problems + /// Removing `::{self}` will cause any non-module items at the same path to also be imported. /// This might cause a naming conflict (https://github.com/rust-lang/rustfmt/issues/3568). This lint makes no attempt /// to detect this scenario and that is why it is a restriction lint. /// - /// **Example:** - /// + /// ### Example /// ```rust /// use std::io::{self}; /// ``` diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 347d858b640..6fc5707a4ee 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -12,21 +12,20 @@ use rustc_span::symbol::Ident; use std::iter; declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Detects uses of `Vec::sort_by` passing in a closure /// which compares the two arguments, either directly or indirectly. /// - /// **Why is this bad?** + /// ### Why is this bad? /// It is more clear to use `Vec::sort_by_key` (or `Vec::sort` if /// possible) than to use `Vec::sort_by` and a more complicated /// closure. /// - /// **Known problems:** + /// ### Known problems /// If the suggested `Vec::sort_by_key` uses Reverse and it isn't already /// imported by a use statement, then it will need to be added manually. /// - /// **Example:** - /// + /// ### Example /// ```rust /// # struct A; /// # impl A { fn foo(&self) {} } diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index a85ffa6aa95..7a62b21937f 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -13,15 +13,17 @@ use rustc_span::symbol::sym; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for private functions that only return `Ok` or `Some`. + /// ### What it does + /// Checks for private functions that only return `Ok` or `Some`. /// - /// **Why is this bad?** It is not meaningful to wrap values when no `None` or `Err` is returned. + /// ### Why is this bad? + /// It is not meaningful to wrap values when no `None` or `Err` is returned. /// - /// **Known problems:** There can be false positives if the function signature is designed to + /// ### Known problems + /// There can be false positives if the function signature is designed to /// fit some external requirement. /// - /// **Example:** - /// + /// ### Example /// ```rust /// fn get_cool_number(a: bool, b: bool) -> Option { /// if a && b { diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 07a4e294049..9acfbc994b3 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -17,22 +17,17 @@ use std::cell::Cell; use std::mem; declare_clippy_lint! { - /// **What it does:** - /// + /// ### What it does /// Checks for unnested or-patterns, e.g., `Some(0) | Some(2)` and /// suggests replacing the pattern with a nested one, `Some(0 | 2)`. /// /// Another way to think of this is that it rewrites patterns in /// *disjunctive normal form (DNF)* into *conjunctive normal form (CNF)*. /// - /// **Why is this bad?** - /// + /// ### Why is this bad? /// In the example above, `Some` is repeated, which unncessarily complicates the pattern. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// fn main() { /// if let Some(0) | Some(2) = Some(0) {} diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 16ad9d2dfd3..3c694af2b9d 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -6,15 +6,15 @@ use rustc_span::source_map::Span; use rustc_span::symbol::Ident; declare_clippy_lint! { - /// **What it does:** Checks for imports that remove "unsafe" from an item's + /// ### What it does + /// Checks for imports that remove "unsafe" from an item's /// name. /// - /// **Why is this bad?** Renaming makes it less clear which traits and + /// ### Why is this bad? + /// Renaming makes it less clear which traits and /// structures are unsafe. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// use std::cell::{UnsafeCell as TotallySafeCell}; /// diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 18ee07d3a95..3a6a07c5226 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -7,16 +7,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; declare_clippy_lint! { - /// **What it does:** Checks for functions that are declared `async` but have no `.await`s inside of them. + /// ### What it does + /// Checks for functions that are declared `async` but have no `.await`s inside of them. /// - /// **Why is this bad?** Async functions with no async code create overhead, both mentally and computationally. + /// ### Why is this bad? + /// Async functions with no async code create overhead, both mentally and computationally. /// Callers of async methods either need to be calling from an async function themselves or run it on an executor, both of which /// causes runtime overhead and hassle for the caller. /// - /// **Known problems:** None - /// - /// **Example:** - /// + /// ### Example /// ```rust /// // Bad /// async fn get_random_number() -> i64 { diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index ee082d30d93..82bc4a6d153 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -5,9 +5,11 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for unused written/read amount. + /// ### What it does + /// Checks for unused written/read amount. /// - /// **Why is this bad?** `io::Write::write(_vectored)` and + /// ### Why is this bad? + /// `io::Write::write(_vectored)` and /// `io::Read::read(_vectored)` are not guaranteed to /// process the entire buffer. They return how many bytes were processed, which /// might be smaller @@ -15,9 +17,10 @@ declare_clippy_lint! { /// partial-write/read, use /// `write_all`/`read_exact` instead. /// - /// **Known problems:** Detects only common patterns. + /// ### Known problems + /// Detects only common patterns. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// use std::io; /// fn foo(w: &mut W) -> io::Result<()> { diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 15343cf90f2..658ac81f6ea 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -6,14 +6,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks methods that contain a `self` argument but don't use it + /// ### What it does + /// Checks methods that contain a `self` argument but don't use it /// - /// **Why is this bad?** It may be clearer to define the method as an associated function instead + /// ### Why is this bad? + /// It may be clearer to define the method as an associated function instead /// of an instance method if it doesn't require `self`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust,ignore /// struct A; /// impl A { diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index ab0cdf75ffe..9ed5e585f84 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -10,15 +10,15 @@ use rustc_span::source_map::Span; use rustc_span::BytePos; declare_clippy_lint! { - /// **What it does:** Checks for unit (`()`) expressions that can be removed. + /// ### What it does + /// Checks for unit (`()`) expressions that can be removed. /// - /// **Why is this bad?** Such expressions add no value, but can make the code + /// ### Why is this bad? + /// Such expressions add no value, but can make the code /// less readable. Depending on formatting they can make a `break` or `return` /// statement look like a function call. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// fn return_unit() -> () { /// () diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index d4efee56eff..c5b8acb9982 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -13,13 +13,13 @@ use rustc_span::source_map::Span; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for calls of `unwrap[_err]()` that cannot fail. + /// ### What it does + /// Checks for calls of `unwrap[_err]()` that cannot fail. /// - /// **Why is this bad?** Using `if let` or `match` is more idiomatic. + /// ### Why is this bad? + /// Using `if let` or `match` is more idiomatic. /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// ```rust /// # let option = Some(0); /// # fn do_something_with(_x: usize) {} @@ -43,14 +43,17 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls of `unwrap[_err]()` that will always fail. + /// ### What it does + /// Checks for calls of `unwrap[_err]()` that will always fail. /// - /// **Why is this bad?** If panicking is desired, an explicit `panic!()` should be used. + /// ### Why is this bad? + /// If panicking is desired, an explicit `panic!()` should be used. /// - /// **Known problems:** This lint only checks `if` conditions not assignments. + /// ### Known problems + /// This lint only checks `if` conditions not assignments. /// So something like `let x: Option<()> = None; x.unwrap();` will not be recognized. /// - /// **Example:** + /// ### Example /// ```rust /// # let option = Some(0); /// # fn do_something_with(_x: usize) {} diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index d17aa6d8424..6eadd1fc1c9 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -12,13 +12,16 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; declare_clippy_lint! { - /// **What it does:** Checks for functions of type Result that contain `expect()` or `unwrap()` + /// ### What it does + /// Checks for functions of type Result that contain `expect()` or `unwrap()` /// - /// **Why is this bad?** These functions promote recoverable errors to non-recoverable errors which may be undesirable in code bases which wish to avoid panics. + /// ### Why is this bad? + /// These functions promote recoverable errors to non-recoverable errors which may be undesirable in code bases which wish to avoid panics. /// - /// **Known problems:** This can cause false positives in functions that handle both recoverable and non recoverable errors. + /// ### Known problems + /// This can cause false positives in functions that handle both recoverable and non recoverable errors. /// - /// **Example:** + /// ### Example /// Before: /// ```rust /// fn divisible_by_3(i_str: String) -> Result<(), String> { diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 0b58c6c0917..7fa0e23ee73 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -8,9 +8,11 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::Ident; declare_clippy_lint! { - /// **What it does:** Checks for fully capitalized names and optionally names containing a capitalized acronym. + /// ### What it does + /// Checks for fully capitalized names and optionally names containing a capitalized acronym. /// - /// **Why is this bad?** In CamelCase, acronyms count as one word. + /// ### Why is this bad? + /// In CamelCase, acronyms count as one word. /// See [naming conventions](https://rust-lang.github.io/api-guidelines/naming.html#casing-conforms-to-rfc-430-c-case) /// for more. /// @@ -18,12 +20,12 @@ declare_clippy_lint! { /// You can use the `upper-case-acronyms-aggressive: true` config option to enable linting /// on all camel case names /// - /// **Known problems:** When two acronyms are contiguous, the lint can't tell where + /// ### Known problems + /// When two acronyms are contiguous, the lint can't tell where /// the first acronym ends and the second starts, so it suggests to lowercase all of /// the letters in the second acronym. /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct HTTPResponse; /// ``` diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 71117e967e3..fbd552186df 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -20,19 +20,20 @@ use rustc_span::Span; use rustc_typeck::hir_ty_to_ty; declare_clippy_lint! { - /// **What it does:** Checks for unnecessary repetition of structure name when a + /// ### What it does + /// Checks for unnecessary repetition of structure name when a /// replacement with `Self` is applicable. /// - /// **Why is this bad?** Unnecessary repetition. Mixed use of `Self` and struct + /// ### Why is this bad? + /// Unnecessary repetition. Mixed use of `Self` and struct /// name /// feels inconsistent. /// - /// **Known problems:** + /// ### Known problems /// - Unaddressed false negative in fn bodies of trait implementations /// - False positive with assotiated types in traits (#4140) /// - /// **Example:** - /// + /// ### Example /// ```rust /// struct Foo {} /// impl Foo { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 25a959d3e41..2861b432919 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -12,15 +12,14 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; declare_clippy_lint! { - /// **What it does:** Checks for `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` calls + /// ### What it does + /// Checks for `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` calls /// which uselessly convert to the same type. /// - /// **Why is this bad?** Redundant code. - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? + /// Redundant code. /// + /// ### Example /// ```rust /// // Bad /// // format!() returns a `String` diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index c1e7fd7fe95..61fd375a989 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -13,9 +13,10 @@ use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Generates clippy code that detects the offending pattern + /// ### What it does + /// Generates clippy code that detects the offending pattern /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // ./tests/ui/my_lint.rs /// fn foo() { diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 4665eeeff7b..f7ddee12dcf 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -8,10 +8,11 @@ use rustc_session::Session; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Dumps every ast/hir node which has the `#[clippy::dump]` + /// ### What it does + /// Dumps every ast/hir node which has the `#[clippy::dump]` /// attribute /// - /// **Example:** + /// ### Example /// ```rust,ignore /// #[clippy::dump] /// extern crate foo; diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 668807f499f..d660008e7d1 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -36,29 +36,33 @@ use std::borrow::{Borrow, Cow}; pub mod metadata_collector; declare_clippy_lint! { - /// **What it does:** Checks for various things we like to keep tidy in clippy. + /// ### What it does + /// Checks for various things we like to keep tidy in clippy. /// - /// **Why is this bad?** We like to pretend we're an example of tidy code. + /// ### Why is this bad? + /// We like to pretend we're an example of tidy code. /// - /// **Known problems:** None. - /// - /// **Example:** Wrong ordering of the util::paths constants. + /// ### Example + /// Wrong ordering of the util::paths constants. pub CLIPPY_LINTS_INTERNAL, internal, "various things that will negatively affect your clippy experience" } declare_clippy_lint! { - /// **What it does:** Ensures every lint is associated to a `LintPass`. + /// ### What it does + /// Ensures every lint is associated to a `LintPass`. /// - /// **Why is this bad?** The compiler only knows lints via a `LintPass`. Without + /// ### Why is this bad? + /// The compiler only knows lints via a `LintPass`. Without /// putting a lint to a `LintPass::get_lints()`'s return, the compiler will not /// know the name of the lint. /// - /// **Known problems:** Only checks for lints associated using the + /// ### Known problems + /// Only checks for lints associated using the /// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// declare_lint! { pub LINT_1, ... } /// declare_lint! { pub LINT_2, ... } @@ -73,15 +77,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `cx.span_lint*` and suggests to use the `utils::*` + /// ### What it does + /// Checks for calls to `cx.span_lint*` and suggests to use the `utils::*` /// variant of the function. /// - /// **Why is this bad?** The `utils::*` variants also add a link to the Clippy documentation to the + /// ### Why is this bad? + /// The `utils::*` variants also add a link to the Clippy documentation to the /// warning/error messages. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// cx.span_lint(LINT_NAME, "message"); @@ -97,14 +101,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `cx.outer().expn_data()` and suggests to use + /// ### What it does + /// Checks for calls to `cx.outer().expn_data()` and suggests to use /// the `cx.outer_expn_data()` /// - /// **Why is this bad?** `cx.outer_expn_data()` is faster and more concise. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// `cx.outer_expn_data()` is faster and more concise. /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// expr.span.ctxt().outer().expn_data() @@ -120,14 +124,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Not an actual lint. This lint is only meant for testing our customized internal compiler + /// ### What it does + /// Not an actual lint. This lint is only meant for testing our customized internal compiler /// error message by calling `panic`. /// - /// **Why is this bad?** ICE in large quantities can damage your teeth + /// ### Why is this bad? + /// ICE in large quantities can damage your teeth /// - /// **Known problems:** None - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// 🍦🍦🍦🍦🍦 @@ -138,14 +142,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for cases of an auto-generated lint without an updated description, + /// ### What it does + /// Checks for cases of an auto-generated lint without an updated description, /// i.e. `default lint description`. /// - /// **Why is this bad?** Indicates that the lint is not finished. - /// - /// **Known problems:** None + /// ### Why is this bad? + /// Indicates that the lint is not finished. /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// declare_lint! { pub COOL_LINT, nursery, "default lint description" } @@ -161,7 +165,8 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Lints `span_lint_and_then` function calls, where the + /// ### What it does + /// Lints `span_lint_and_then` function calls, where the /// closure argument has only one statement and that statement is a method /// call to `span_suggestion`, `span_help`, `span_note` (using the same /// span), `help` or `note`. @@ -170,12 +175,11 @@ declare_clippy_lint! { /// wrapper functions `span_lint_and_sugg`, span_lint_and_help`, or /// `span_lint_and_note`. /// - /// **Why is this bad?** Using the wrapper `span_lint_and_*` functions, is more + /// ### Why is this bad? + /// Using the wrapper `span_lint_and_*` functions, is more /// convenient, readable and less error prone. /// - /// **Known problems:** None - /// - /// *Example:** + /// ### Example /// Bad: /// ```rust,ignore /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| { @@ -222,14 +226,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for calls to `utils::match_type()` on a type diagnostic item + /// ### What it does + /// Checks for calls to `utils::match_type()` on a type diagnostic item /// and suggests to use `utils::is_type_diagnostic_item()` instead. /// - /// **Why is this bad?** `utils::is_type_diagnostic_item()` does not require hardcoded paths. - /// - /// **Known problems:** None. + /// ### Why is this bad? + /// `utils::is_type_diagnostic_item()` does not require hardcoded paths. /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// utils::match_type(cx, ty, &paths::VEC) @@ -245,30 +249,27 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Checks the paths module for invalid paths. /// - /// **Why is this bad?** + /// ### Why is this bad? /// It indicates a bug in the code. /// - /// **Known problems:** None. - /// - /// **Example:** None. + /// ### Example + /// None. pub INVALID_PATHS, internal, "invalid path" } declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// Checks for interning symbols that have already been pre-interned and defined as constants. /// - /// **Why is this bad?** + /// ### Why is this bad? /// It's faster and easier to use the symbol constant. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// let _ = sym!(f32); @@ -284,13 +285,13 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for unnecessary conversion from Symbol to a string. - /// - /// **Why is this bad?** It's faster use symbols directly intead of strings. + /// ### What it does + /// Checks for unnecessary conversion from Symbol to a string. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// It's faster use symbols directly intead of strings. /// - /// **Example:** + /// ### Example /// Bad: /// ```rust,ignore /// symbol.as_str() == "clippy"; diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 3eccc89cdeb..3244677b301 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -68,7 +68,7 @@ const CLIPPY_LINT_GROUP_PREFIX: &str = "clippy::"; macro_rules! CONFIGURATION_SECTION_TEMPLATE { () => { r#" -**Configuration** +### Configuration This lint has the following configuration variables: {configurations} @@ -116,18 +116,21 @@ const DEPRECATED_LINT_TYPE: [&str; 3] = ["clippy_lints", "deprecated_lints", "Cl const APPLICABILITY_NAME_INDEX: usize = 2; declare_clippy_lint! { - /// **What it does:** Collects metadata about clippy lints for the website. + /// ### What it does + /// Collects metadata about clippy lints for the website. /// /// This lint will be used to report problems of syntax parsing. You should hopefully never /// see this but never say never I guess ^^ /// - /// **Why is this bad?** This is not a bad thing but definitely a hacky way to do it. See + /// ### Why is this bad? + /// This is not a bad thing but definitely a hacky way to do it. See /// issue [#4310](https://github.com/rust-lang/rust-clippy/issues/4310) for a discussion /// about the implementation. /// - /// **Known problems:** Hopefully none. It would be pretty uncool to have a problem here :) + /// ### Known problems + /// Hopefully none. It would be pretty uncool to have a problem here :) /// - /// **Example output:** + /// ### Example output /// ```json,ignore /// { /// "id": "internal_metadata_collector", @@ -374,7 +377,8 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector { /// Collecting lint declarations like: /// ```rust, ignore /// declare_clippy_lint! { - /// /// **What it does:** Something IDK. + /// /// ### What it does + /// /// Something IDK. /// pub SOME_LINT, /// internal, /// "Who am I?" diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 1d5b7c98d31..32fa46f042c 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -19,14 +19,14 @@ pub struct UselessVec { } declare_clippy_lint! { - /// **What it does:** Checks for usage of `&vec![..]` when using `&[..]` would + /// ### What it does + /// Checks for usage of `&vec![..]` when using `&[..]` would /// be possible. /// - /// **Why is this bad?** This is less efficient. + /// ### Why is this bad? + /// This is less efficient. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # fn foo(my_vec: &[u8]) {} /// diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index c7190e2f979..0413c02b230 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -13,15 +13,14 @@ use rustc_span::{symbol::sym, Span}; use std::convert::TryInto; declare_clippy_lint! { - /// **What it does:** Checks for calls to `push` immediately after creating a new `Vec`. + /// ### What it does + /// Checks for calls to `push` immediately after creating a new `Vec`. /// - /// **Why is this bad?** The `vec![]` macro is both more performant and easier to read than + /// ### Why is this bad? + /// The `vec![]` macro is both more performant and easier to read than /// multiple `push` calls. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust /// let mut v = Vec::new(); /// v.push(0); diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index 5540e87405f..5c0429db6b8 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -10,13 +10,13 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; declare_clippy_lint! { - /// **What it does:** Finds occurrences of `Vec::resize(0, an_int)` + /// ### What it does + /// Finds occurrences of `Vec::resize(0, an_int)` /// - /// **Why is this bad?** This is probably an argument inversion mistake. + /// ### Why is this bad? + /// This is probably an argument inversion mistake. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// vec!(1, 2, 3, 4, 5).resize(0, 5) /// ``` diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index 3ab68df2b6d..e07c12f4f16 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -7,15 +7,14 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for use of File::read_to_end and File::read_to_string. + /// ### What it does + /// Checks for use of File::read_to_end and File::read_to_string. /// - /// **Why is this bad?** `fs::{read, read_to_string}` provide the same functionality when `buf` is empty with fewer imports and no intermediate values. + /// ### Why is this bad? + /// `fs::{read, read_to_string}` provide the same functionality when `buf` is empty with fewer imports and no intermediate values. /// See also: [fs::read docs](https://doc.rust-lang.org/std/fs/fn.read.html), [fs::read_to_string docs](https://doc.rust-lang.org/std/fs/fn.read_to_string.html) /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```rust,no_run /// # use std::io::Read; /// # use std::fs::File; diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index 1ca1117a41e..fd3872bacbe 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -7,16 +7,15 @@ use rustc_span::source_map::DUMMY_SP; use if_chain::if_chain; declare_clippy_lint! { - /// **What it does:** Checks for wildcard dependencies in the `Cargo.toml`. + /// ### What it does + /// Checks for wildcard dependencies in the `Cargo.toml`. /// - /// **Why is this bad?** [As the edition guide says](https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html), + /// ### Why is this bad? + /// [As the edition guide says](https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html), /// it is highly unlikely that you work with any possible version of your dependency, /// and wildcard dependencies would cause unnecessary breakage in the ecosystem. /// - /// **Known problems:** None. - /// - /// **Example:** - /// + /// ### Example /// ```toml /// [dependencies] /// regex = "*" diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 520586b3a1f..bafb9d3e3b1 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -13,15 +13,18 @@ use rustc_span::symbol::kw; use rustc_span::{sym, BytePos}; declare_clippy_lint! { - /// **What it does:** Checks for `use Enum::*`. + /// ### What it does + /// Checks for `use Enum::*`. /// - /// **Why is this bad?** It is usually better style to use the prefixed name of + /// ### Why is this bad? + /// It is usually better style to use the prefixed name of /// an enumeration variant, rather than importing variants. /// - /// **Known problems:** Old-style enumerations that prefix the variants are + /// ### Known problems + /// Old-style enumerations that prefix the variants are /// still around. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// // Bad /// use std::cmp::Ordering::*; @@ -37,9 +40,11 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for wildcard imports `use _::*`. + /// ### What it does + /// Checks for wildcard imports `use _::*`. /// - /// **Why is this bad?** wildcard imports can pollute the namespace. This is especially bad if + /// ### Why is this bad? + /// wildcard imports can pollute the namespace. This is especially bad if /// you try to import something through a wildcard, that already has been imported by name from /// a different source: /// @@ -52,8 +57,7 @@ declare_clippy_lint! { /// /// This can lead to confusing error messages at best and to unexpected behavior at worst. /// - /// **Exceptions:** - /// + /// ### Exceptions /// Wildcard imports are allowed from modules named `prelude`. Many crates (including the standard library) /// provide modules named "prelude" specifically designed for wildcard import. /// @@ -61,14 +65,14 @@ declare_clippy_lint! { /// /// These exceptions can be disabled using the `warn-on-all-wildcard-imports` configuration flag. /// - /// **Known problems:** If macros are imported through the wildcard, this macro is not included + /// ### Known problems + /// If macros are imported through the wildcard, this macro is not included /// by the suggestion and has to be added by hand. /// /// Applying the suggestion when explicit imports of the things imported with a glob import /// exist, may result in `unused_imports` warnings. /// - /// **Example:** - /// + /// ### Example /// ```rust,ignore /// // Bad /// use crate1::*; diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 5229a705865..4553ac704a2 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -16,14 +16,14 @@ use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, BytePos, Span, DUMMY_SP}; declare_clippy_lint! { - /// **What it does:** This lint warns when you use `println!("")` to + /// ### What it does + /// This lint warns when you use `println!("")` to /// print a newline. /// - /// **Why is this bad?** You should use `println!()`, which is simpler. + /// ### Why is this bad? + /// You should use `println!()`, which is simpler. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// println!(""); @@ -37,15 +37,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint warns when you use `print!()` with a format + /// ### What it does + /// This lint warns when you use `print!()` with a format /// string that ends in a newline. /// - /// **Why is this bad?** You should use `println!()` instead, which appends the + /// ### Why is this bad? + /// You should use `println!()` instead, which appends the /// newline. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # let name = "World"; /// print!("Hello {}!\n", name); @@ -61,15 +61,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for printing on *stdout*. The purpose of this lint + /// ### What it does + /// Checks for printing on *stdout*. The purpose of this lint /// is to catch debugging remnants. /// - /// **Why is this bad?** People often print on *stdout* while debugging an + /// ### Why is this bad? + /// People often print on *stdout* while debugging an /// application and might forget to remove those prints afterward. /// - /// **Known problems:** Only catches `print!` and `println!` calls. + /// ### Known problems + /// Only catches `print!` and `println!` calls. /// - /// **Example:** + /// ### Example /// ```rust /// println!("Hello world!"); /// ``` @@ -79,15 +82,18 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for printing on *stderr*. The purpose of this lint + /// ### What it does + /// Checks for printing on *stderr*. The purpose of this lint /// is to catch debugging remnants. /// - /// **Why is this bad?** People often print on *stderr* while debugging an + /// ### Why is this bad? + /// People often print on *stderr* while debugging an /// application and might forget to remove those prints afterward. /// - /// **Known problems:** Only catches `eprint!` and `eprintln!` calls. + /// ### Known problems + /// Only catches `eprint!` and `eprintln!` calls. /// - /// **Example:** + /// ### Example /// ```rust /// eprintln!("Hello world!"); /// ``` @@ -97,13 +103,15 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** Checks for use of `Debug` formatting. The purpose of this + /// ### What it does + /// Checks for use of `Debug` formatting. The purpose of this /// lint is to catch debugging remnants. /// - /// **Why is this bad?** The purpose of the `Debug` trait is to facilitate + /// ### Why is this bad? + /// The purpose of the `Debug` trait is to facilitate /// debugging Rust code. It should not be used in user-facing output. /// - /// **Example:** + /// ### Example /// ```rust /// # let foo = "bar"; /// println!("{:?}", foo); @@ -114,16 +122,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint warns about the use of literals as `print!`/`println!` args. + /// ### What it does + /// This lint warns about the use of literals as `print!`/`println!` args. /// - /// **Why is this bad?** Using literals as `println!` args is inefficient + /// ### Why is this bad? + /// Using literals as `println!` args is inefficient /// (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary /// (i.e., just put the literal in the format string) /// - /// **Known problems:** Will also warn with macro calls as arguments that expand to literals + /// ### Known problems + /// Will also warn with macro calls as arguments that expand to literals /// -- e.g., `println!("{}", env!("FOO"))`. /// - /// **Example:** + /// ### Example /// ```rust /// println!("{}", "foo"); /// ``` @@ -137,14 +148,14 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint warns when you use `writeln!(buf, "")` to + /// ### What it does + /// This lint warns when you use `writeln!(buf, "")` to /// print a newline. /// - /// **Why is this bad?** You should use `writeln!(buf)`, which is simpler. + /// ### Why is this bad? + /// You should use `writeln!(buf)`, which is simpler. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use std::fmt::Write; /// # let mut buf = String::new(); @@ -160,16 +171,16 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint warns when you use `write!()` with a format + /// ### What it does + /// This lint warns when you use `write!()` with a format /// string that /// ends in a newline. /// - /// **Why is this bad?** You should use `writeln!()` instead, which appends the + /// ### Why is this bad? + /// You should use `writeln!()` instead, which appends the /// newline. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// # use std::fmt::Write; /// # let mut buf = String::new(); @@ -186,16 +197,19 @@ declare_clippy_lint! { } declare_clippy_lint! { - /// **What it does:** This lint warns about the use of literals as `write!`/`writeln!` args. + /// ### What it does + /// This lint warns about the use of literals as `write!`/`writeln!` args. /// - /// **Why is this bad?** Using literals as `writeln!` args is inefficient + /// ### Why is this bad? + /// Using literals as `writeln!` args is inefficient /// (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary /// (i.e., just put the literal in the format string) /// - /// **Known problems:** Will also warn with macro calls as arguments that expand to literals + /// ### Known problems + /// Will also warn with macro calls as arguments that expand to literals /// -- e.g., `writeln!(buf, "{}", env!("FOO"))`. /// - /// **Example:** + /// ### Example /// ```rust /// # use std::fmt::Write; /// # let mut buf = String::new(); diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index a1ea743ba80..b29ced28ac4 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -6,13 +6,13 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { - /// **What it does:** Checks for `0.0 / 0.0`. + /// ### What it does + /// Checks for `0.0 / 0.0`. /// - /// **Why is this bad?** It's less readable than `f32::NAN` or `f64::NAN`. + /// ### Why is this bad? + /// It's less readable than `f32::NAN` or `f64::NAN`. /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Example /// ```rust /// // Bad /// let nan = 0.0f32 / 0.0; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index d6a8112218f..2fbe27f9479 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -10,18 +10,19 @@ use rustc_target::abi::LayoutOf as _; use rustc_typeck::hir_ty_to_ty; declare_clippy_lint! { - /// **What it does:** Checks for maps with zero-sized value types anywhere in the code. + /// ### What it does + /// Checks for maps with zero-sized value types anywhere in the code. /// - /// **Why is this bad?** Since there is only a single value for a zero-sized type, a map + /// ### Why is this bad? + /// Since there is only a single value for a zero-sized type, a map /// containing zero sized values is effectively a set. Using a set in that case improves /// readability and communicates intent more clearly. /// - /// **Known problems:** + /// ### Known problems /// * A zero-sized type cannot be recovered later if it contains private fields. /// * This lints the signature of public items /// - /// **Example:** - /// + /// ### Example /// ```rust /// # use std::collections::HashMap; /// fn unique_words(text: &str) -> HashMap<&str, ()> { diff --git a/doc/adding_lints.md b/doc/adding_lints.md index 5a06afedbf4..f2260c3d1a2 100644 --- a/doc/adding_lints.md +++ b/doc/adding_lints.md @@ -11,6 +11,7 @@ because that's clearly a non-descriptive name. - [Setup](#setup) - [Getting Started](#getting-started) - [Testing](#testing) + - [Cargo lints](#cargo-lints) - [Rustfix tests](#rustfix-tests) - [Edition 2018 tests](#edition-2018-tests) - [Testing manually](#testing-manually) @@ -179,14 +180,11 @@ the auto-generated lint declaration to have a real description, something like t ```rust declare_clippy_lint! { - /// **What it does:** + /// ### What it does /// - /// **Why is this bad?** - /// - /// **Known problems:** None. - /// - /// **Example:** + /// ### Why is this bad? /// + /// ### Example /// ```rust /// // example code /// ``` @@ -487,13 +485,13 @@ Please document your lint with a doc comment akin to the following: ```rust declare_clippy_lint! { - /// **What it does:** Checks for ... (describe what the lint matches). - /// - /// **Why is this bad?** Supply the reason for linting the code. + /// ### What it does + /// Checks for ... (describe what the lint matches). /// - /// **Known problems:** None. (Or describe where it could go wrong.) + /// ### Why is this bad? + /// Supply the reason for linting the code. /// - /// **Example:** + /// ### Example /// /// ```rust,ignore /// // Bad -- cgit 1.4.1-3-g733a5 From d647696c1f167802c9bb9ffe2c98459b152d563c Mon Sep 17 00:00:00 2001 From: xFrednet Date: Thu, 21 Oct 2021 21:06:26 +0200 Subject: Added `clippy::version` attribute to all normal lints So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`... And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun... Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work. ```nu mv v0.0.212 rust-1.00.0; mv beta rust-1.57.0; mv master rust-1.58.0; let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path); let versions = ( ls | where name =~ "rust-" | select name | format {name}/lints.json | each { open $it | select id | insert version $it | str substring "5,11" version} | group-by id | rotate counter-clockwise id version | update version {get version | first 1} | flatten | select id version); $paths | each { |row| let version = ($versions | where id == ($row.id) | format {version}) let idu = ($row.id | str upcase) $"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n pub ($idu),/}' ($row.path)" } | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh"; ``` And this still has some problems, but at this point I just want to be done -.- --- clippy_lints/src/absurd_extreme_comparisons.rs | 1 + clippy_lints/src/approx_const.rs | 1 + clippy_lints/src/arithmetic.rs | 2 + clippy_lints/src/as_conversions.rs | 1 + clippy_lints/src/asm_syntax.rs | 2 + clippy_lints/src/assertions_on_constants.rs | 1 + clippy_lints/src/assign_ops.rs | 2 + clippy_lints/src/async_yields_async.rs | 1 + clippy_lints/src/attrs.rs | 7 +++ clippy_lints/src/await_holding_invalid.rs | 2 + clippy_lints/src/bit_mask.rs | 3 ++ clippy_lints/src/blacklisted_name.rs | 1 + clippy_lints/src/blocks_in_if_conditions.rs | 1 + clippy_lints/src/bool_assert_comparison.rs | 1 + clippy_lints/src/booleans.rs | 2 + clippy_lints/src/bytecount.rs | 1 + clippy_lints/src/cargo_common_metadata.rs | 1 + .../case_sensitive_file_extension_comparisons.rs | 1 + clippy_lints/src/casts/mod.rs | 13 +++++ clippy_lints/src/checked_conversions.rs | 1 + clippy_lints/src/cognitive_complexity.rs | 1 + clippy_lints/src/collapsible_if.rs | 2 + clippy_lints/src/collapsible_match.rs | 1 + clippy_lints/src/comparison_chain.rs | 1 + clippy_lints/src/copies.rs | 4 ++ clippy_lints/src/copy_iterator.rs | 1 + clippy_lints/src/create_dir.rs | 1 + clippy_lints/src/dbg_macro.rs | 1 + clippy_lints/src/default.rs | 2 + clippy_lints/src/default_numeric_fallback.rs | 1 + clippy_lints/src/dereference.rs | 1 + clippy_lints/src/derivable_impls.rs | 1 + clippy_lints/src/derive.rs | 4 ++ clippy_lints/src/disallowed_method.rs | 1 + clippy_lints/src/disallowed_script_idents.rs | 1 + clippy_lints/src/disallowed_type.rs | 1 + clippy_lints/src/doc.rs | 5 ++ clippy_lints/src/double_comparison.rs | 1 + clippy_lints/src/double_parens.rs | 1 + clippy_lints/src/drop_forget_ref.rs | 4 ++ clippy_lints/src/duration_subsec.rs | 1 + clippy_lints/src/else_if_without_else.rs | 1 + clippy_lints/src/empty_enum.rs | 1 + clippy_lints/src/entry.rs | 1 + clippy_lints/src/enum_clike.rs | 1 + clippy_lints/src/enum_variants.rs | 3 ++ clippy_lints/src/eq_op.rs | 2 + clippy_lints/src/equatable_if_let.rs | 1 + clippy_lints/src/erasing_op.rs | 1 + clippy_lints/src/escape.rs | 1 + clippy_lints/src/eta_reduction.rs | 2 + clippy_lints/src/eval_order_dependence.rs | 2 + clippy_lints/src/excessive_bools.rs | 2 + clippy_lints/src/exhaustive_items.rs | 2 + clippy_lints/src/exit.rs | 1 + clippy_lints/src/explicit_write.rs | 1 + clippy_lints/src/fallible_impl_from.rs | 1 + clippy_lints/src/feature_name.rs | 2 + clippy_lints/src/float_equality_without_abs.rs | 1 + clippy_lints/src/float_literal.rs | 2 + clippy_lints/src/floating_point_arithmetic.rs | 2 + clippy_lints/src/format.rs | 1 + clippy_lints/src/format_args.rs | 2 + clippy_lints/src/formatting.rs | 4 ++ clippy_lints/src/from_over_into.rs | 1 + clippy_lints/src/from_str_radix_10.rs | 1 + clippy_lints/src/functions/mod.rs | 7 +++ clippy_lints/src/future_not_send.rs | 1 + clippy_lints/src/get_last_with_len.rs | 1 + clippy_lints/src/identity_op.rs | 1 + clippy_lints/src/if_let_mutex.rs | 1 + clippy_lints/src/if_not_else.rs | 1 + clippy_lints/src/if_then_some_else_none.rs | 1 + clippy_lints/src/implicit_hasher.rs | 1 + clippy_lints/src/implicit_return.rs | 1 + clippy_lints/src/implicit_saturating_sub.rs | 1 + .../src/inconsistent_struct_constructor.rs | 1 + clippy_lints/src/indexing_slicing.rs | 2 + clippy_lints/src/infinite_iter.rs | 2 + clippy_lints/src/inherent_impl.rs | 1 + clippy_lints/src/inherent_to_string.rs | 2 + clippy_lints/src/inline_fn_without_body.rs | 1 + clippy_lints/src/int_plus_one.rs | 1 + clippy_lints/src/integer_division.rs | 1 + clippy_lints/src/invalid_upcast_comparisons.rs | 1 + clippy_lints/src/items_after_statements.rs | 1 + clippy_lints/src/iter_not_returning_iterator.rs | 1 + clippy_lints/src/large_const_arrays.rs | 1 + clippy_lints/src/large_enum_variant.rs | 1 + clippy_lints/src/large_stack_arrays.rs | 1 + clippy_lints/src/len_zero.rs | 3 ++ clippy_lints/src/let_if_seq.rs | 1 + clippy_lints/src/let_underscore.rs | 3 ++ clippy_lints/src/lifetimes.rs | 2 + clippy_lints/src/literal_representation.rs | 6 +++ clippy_lints/src/loops/mod.rs | 18 +++++++ clippy_lints/src/macro_use.rs | 1 + clippy_lints/src/main_recursion.rs | 1 + clippy_lints/src/manual_assert.rs | 1 + clippy_lints/src/manual_async_fn.rs | 1 + clippy_lints/src/manual_map.rs | 1 + clippy_lints/src/manual_non_exhaustive.rs | 1 + clippy_lints/src/manual_ok_or.rs | 1 + clippy_lints/src/manual_strip.rs | 1 + clippy_lints/src/manual_unwrap_or.rs | 1 + clippy_lints/src/map_clone.rs | 1 + clippy_lints/src/map_err_ignore.rs | 1 + clippy_lints/src/map_unit_fn.rs | 2 + clippy_lints/src/match_on_vec_items.rs | 1 + clippy_lints/src/match_result_ok.rs | 1 + clippy_lints/src/match_str_case_mismatch.rs | 1 + clippy_lints/src/matches.rs | 16 ++++++ clippy_lints/src/mem_forget.rs | 1 + clippy_lints/src/mem_replace.rs | 3 ++ clippy_lints/src/methods/mod.rs | 63 ++++++++++++++++++++++ clippy_lints/src/minmax.rs | 1 + clippy_lints/src/misc.rs | 9 ++++ clippy_lints/src/misc_early/mod.rs | 9 ++++ clippy_lints/src/missing_const_for_fn.rs | 1 + clippy_lints/src/missing_doc.rs | 1 + clippy_lints/src/missing_enforced_import_rename.rs | 1 + clippy_lints/src/missing_inline.rs | 1 + clippy_lints/src/module_style.rs | 2 + clippy_lints/src/modulo_arithmetic.rs | 1 + clippy_lints/src/multiple_crate_versions.rs | 1 + clippy_lints/src/mut_key.rs | 1 + clippy_lints/src/mut_mut.rs | 1 + clippy_lints/src/mut_mutex_lock.rs | 1 + clippy_lints/src/mut_reference.rs | 1 + clippy_lints/src/mutable_debug_assertion.rs | 1 + clippy_lints/src/mutex_atomic.rs | 2 + clippy_lints/src/needless_arbitrary_self_type.rs | 1 + clippy_lints/src/needless_bitwise_bool.rs | 1 + clippy_lints/src/needless_bool.rs | 2 + clippy_lints/src/needless_borrow.rs | 2 + clippy_lints/src/needless_borrowed_ref.rs | 1 + clippy_lints/src/needless_continue.rs | 1 + clippy_lints/src/needless_for_each.rs | 1 + clippy_lints/src/needless_option_as_deref.rs | 1 + clippy_lints/src/needless_pass_by_value.rs | 1 + clippy_lints/src/needless_question_mark.rs | 1 + clippy_lints/src/needless_update.rs | 1 + clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 1 + clippy_lints/src/neg_multiply.rs | 1 + clippy_lints/src/new_without_default.rs | 1 + clippy_lints/src/no_effect.rs | 3 ++ clippy_lints/src/non_copy_const.rs | 2 + clippy_lints/src/non_expressive_names.rs | 3 ++ clippy_lints/src/non_octal_unix_permissions.rs | 1 + clippy_lints/src/non_send_fields_in_send_ty.rs | 1 + clippy_lints/src/nonstandard_macro_braces.rs | 1 + clippy_lints/src/open_options.rs | 1 + clippy_lints/src/option_env_unwrap.rs | 1 + clippy_lints/src/option_if_let_else.rs | 1 + clippy_lints/src/overflow_check_conditional.rs | 1 + clippy_lints/src/panic_in_result_fn.rs | 1 + clippy_lints/src/panic_unimplemented.rs | 4 ++ clippy_lints/src/partialeq_ne_impl.rs | 1 + clippy_lints/src/pass_by_ref_or_value.rs | 2 + clippy_lints/src/path_buf_push_overwrite.rs | 1 + clippy_lints/src/pattern_type_mismatch.rs | 1 + clippy_lints/src/precedence.rs | 1 + clippy_lints/src/ptr.rs | 4 ++ clippy_lints/src/ptr_eq.rs | 1 + clippy_lints/src/ptr_offset_with_cast.rs | 1 + clippy_lints/src/question_mark.rs | 1 + clippy_lints/src/ranges.rs | 5 ++ clippy_lints/src/redundant_clone.rs | 1 + clippy_lints/src/redundant_closure_call.rs | 1 + clippy_lints/src/redundant_else.rs | 1 + clippy_lints/src/redundant_field_names.rs | 1 + clippy_lints/src/redundant_pub_crate.rs | 1 + clippy_lints/src/redundant_slicing.rs | 1 + clippy_lints/src/redundant_static_lifetimes.rs | 1 + clippy_lints/src/ref_option_ref.rs | 1 + clippy_lints/src/reference.rs | 2 + clippy_lints/src/regex.rs | 2 + clippy_lints/src/repeat_once.rs | 1 + clippy_lints/src/returns.rs | 2 + clippy_lints/src/same_name_method.rs | 1 + clippy_lints/src/self_assignment.rs | 1 + clippy_lints/src/self_named_constructors.rs | 1 + clippy_lints/src/semicolon_if_nothing_returned.rs | 1 + clippy_lints/src/serde_api.rs | 1 + clippy_lints/src/shadow.rs | 3 ++ clippy_lints/src/single_component_path_imports.rs | 1 + clippy_lints/src/size_of_in_element_count.rs | 1 + clippy_lints/src/slow_vector_initialization.rs | 1 + clippy_lints/src/stable_sort_primitive.rs | 1 + clippy_lints/src/strings.rs | 7 +++ clippy_lints/src/strlen_on_c_strings.rs | 1 + clippy_lints/src/suspicious_operation_groupings.rs | 1 + clippy_lints/src/suspicious_trait_impl.rs | 2 + clippy_lints/src/swap.rs | 2 + clippy_lints/src/tabs_in_doc_comments.rs | 1 + clippy_lints/src/temporary_assignment.rs | 1 + clippy_lints/src/to_digit_is_some.rs | 1 + clippy_lints/src/to_string_in_display.rs | 1 + clippy_lints/src/trailing_empty_array.rs | 1 + clippy_lints/src/trait_bounds.rs | 2 + clippy_lints/src/transmute/mod.rs | 13 +++++ clippy_lints/src/transmuting_null.rs | 1 + clippy_lints/src/try_err.rs | 1 + clippy_lints/src/types/mod.rs | 9 ++++ clippy_lints/src/undocumented_unsafe_blocks.rs | 1 + clippy_lints/src/undropped_manually_drops.rs | 1 + clippy_lints/src/unicode.rs | 3 ++ clippy_lints/src/uninit_vec.rs | 1 + clippy_lints/src/unit_hash.rs | 1 + clippy_lints/src/unit_return_expecting_ord.rs | 1 + clippy_lints/src/unit_types/mod.rs | 3 ++ clippy_lints/src/unnamed_address.rs | 2 + clippy_lints/src/unnecessary_self_imports.rs | 1 + clippy_lints/src/unnecessary_sort_by.rs | 1 + clippy_lints/src/unnecessary_wraps.rs | 1 + clippy_lints/src/unnested_or_patterns.rs | 1 + clippy_lints/src/unsafe_removed_from_name.rs | 1 + clippy_lints/src/unused_async.rs | 1 + clippy_lints/src/unused_io_amount.rs | 1 + clippy_lints/src/unused_self.rs | 1 + clippy_lints/src/unused_unit.rs | 1 + clippy_lints/src/unwrap.rs | 2 + clippy_lints/src/unwrap_in_result.rs | 1 + clippy_lints/src/upper_case_acronyms.rs | 1 + clippy_lints/src/use_self.rs | 1 + clippy_lints/src/useless_conversion.rs | 1 + clippy_lints/src/vec.rs | 1 + clippy_lints/src/vec_init_then_push.rs | 1 + clippy_lints/src/vec_resize_to_zero.rs | 1 + clippy_lints/src/verbose_file_reads.rs | 1 + clippy_lints/src/wildcard_dependencies.rs | 1 + clippy_lints/src/wildcard_imports.rs | 2 + clippy_lints/src/write.rs | 9 ++++ clippy_lints/src/zero_div_zero.rs | 1 + clippy_lints/src/zero_sized_map_values.rs | 1 + 235 files changed, 490 insertions(+) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/absurd_extreme_comparisons.rs b/clippy_lints/src/absurd_extreme_comparisons.rs index 1483f3f9185..7665aa8380b 100644 --- a/clippy_lints/src/absurd_extreme_comparisons.rs +++ b/clippy_lints/src/absurd_extreme_comparisons.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// if vec.len() <= 0 {} /// if 100 > i32::MAX {} /// ``` + #[clippy::version = "pre 1.29.0"] pub ABSURD_EXTREME_COMPARISONS, correctness, "a comparison with a maximum or minimum value that is always true or false" diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index fb54ac1ec51..12435eefbc4 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// let x = std::f32::consts::PI; /// let y = std::f64::consts::FRAC_1_PI; /// ``` + #[clippy::version = "pre 1.29.0"] pub APPROX_CONSTANT, correctness, "the approximate of a known float constant (in `std::fXX::consts`)" diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 36fe7b7a867..e0c1d6ab6e1 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -25,6 +25,7 @@ declare_clippy_lint! { /// # let a = 0; /// a + 1; /// ``` + #[clippy::version = "pre 1.29.0"] pub INTEGER_ARITHMETIC, restriction, "any integer arithmetic expression which could overflow or panic" @@ -43,6 +44,7 @@ declare_clippy_lint! { /// # let a = 0.0; /// a + 1.0; /// ``` + #[clippy::version = "pre 1.29.0"] pub FLOAT_ARITHMETIC, restriction, "any floating-point arithmetic statement" diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index 0be460d67a7..53704da1046 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -38,6 +38,7 @@ declare_clippy_lint! { /// f(a.try_into().expect("Unexpected u16 overflow in f")); /// ``` /// + #[clippy::version = "1.41.0"] pub AS_CONVERSIONS, restriction, "using a potentially dangerous silent `as` conversion" diff --git a/clippy_lints/src/asm_syntax.rs b/clippy_lints/src/asm_syntax.rs index 825832eb79d..0322698f029 100644 --- a/clippy_lints/src/asm_syntax.rs +++ b/clippy_lints/src/asm_syntax.rs @@ -75,6 +75,7 @@ declare_clippy_lint! { /// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax)); /// # } /// ``` + #[clippy::version = "1.49.0"] pub INLINE_ASM_X86_INTEL_SYNTAX, restriction, "prefer AT&T x86 assembly syntax" @@ -111,6 +112,7 @@ declare_clippy_lint! { /// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr); /// # } /// ``` + #[clippy::version = "1.49.0"] pub INLINE_ASM_X86_ATT_SYNTAX, restriction, "prefer Intel x86 assembly syntax" diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index d834a1d317a..521fc84ee9c 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// const B: bool = false; /// assert!(B) /// ``` + #[clippy::version = "1.34.0"] pub ASSERTIONS_ON_CONSTANTS, style, "`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`" diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 2097a1feff9..e16f4369da9 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// // Good /// a += b; /// ``` + #[clippy::version = "pre 1.29.0"] pub ASSIGN_OP_PATTERN, style, "assigning the result of an operation on a variable to that same variable" @@ -60,6 +61,7 @@ declare_clippy_lint! { /// // ... /// a += a + b; /// ``` + #[clippy::version = "pre 1.29.0"] pub MISREFACTORED_ASSIGN_OP, suspicious, "having a variable on both sides of an assign op" diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index 182736a5a20..0619490e73c 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// }; /// } /// ``` + #[clippy::version = "1.48.0"] pub ASYNC_YIELDS_ASYNC, correctness, "async blocks that return a type that can be awaited" diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 9c5db18336f..1edb7c950e7 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -66,6 +66,7 @@ declare_clippy_lint! { /// #[inline(always)] /// fn not_quite_hot_code(..) { ... } /// ``` + #[clippy::version = "pre 1.29.0"] pub INLINE_ALWAYS, pedantic, "use of `#[inline(always)]`" @@ -100,6 +101,7 @@ declare_clippy_lint! { /// #[macro_use] /// extern crate baz; /// ``` + #[clippy::version = "pre 1.29.0"] pub USELESS_ATTRIBUTE, correctness, "use of lint attributes on `extern crate` items" @@ -119,6 +121,7 @@ declare_clippy_lint! { /// #[deprecated(since = "forever")] /// fn something_else() { /* ... */ } /// ``` + #[clippy::version = "pre 1.29.0"] pub DEPRECATED_SEMVER, correctness, "use of `#[deprecated(since = \"x\")]` where x is not semver" @@ -156,6 +159,7 @@ declare_clippy_lint! { /// #[allow(dead_code)] /// fn this_is_fine_too() { } /// ``` + #[clippy::version = "pre 1.29.0"] pub EMPTY_LINE_AFTER_OUTER_ATTR, nursery, "empty line after outer attribute" @@ -179,6 +183,7 @@ declare_clippy_lint! { /// ```rust /// #![deny(clippy::as_conversions)] /// ``` + #[clippy::version = "1.47.0"] pub BLANKET_CLIPPY_RESTRICTION_LINTS, suspicious, "enabling the complete restriction group" @@ -210,6 +215,7 @@ declare_clippy_lint! { /// #[rustfmt::skip] /// fn main() { } /// ``` + #[clippy::version = "1.32.0"] pub DEPRECATED_CFG_ATTR, complexity, "usage of `cfg_attr(rustfmt)` instead of tool attributes" @@ -242,6 +248,7 @@ declare_clippy_lint! { /// fn conditional() { } /// ``` /// Check the [Rust Reference](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) for more details. + #[clippy::version = "1.45.0"] pub MISMATCHED_TARGET_OS, correctness, "usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`" diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 28615b9217c..1cc3418d474 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -47,6 +47,7 @@ declare_clippy_lint! { /// bar.await; /// } /// ``` + #[clippy::version = "1.45.0"] pub AWAIT_HOLDING_LOCK, pedantic, "Inside an async function, holding a MutexGuard while calling await" @@ -88,6 +89,7 @@ declare_clippy_lint! { /// bar.await; /// } /// ``` + #[clippy::version = "1.49.0"] pub AWAIT_HOLDING_REFCELL_REF, pedantic, "Inside an async function, holding a RefCell ref while calling await" diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 11346e7c96a..0977cf22b2c 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// # let x = 1; /// if (x & 1 == 2) { } /// ``` + #[clippy::version = "pre 1.29.0"] pub BAD_BIT_MASK, correctness, "expressions of the form `_ & mask == select` that will only ever return `true` or `false`" @@ -73,6 +74,7 @@ declare_clippy_lint! { /// # let x = 1; /// if (x | 1 > 3) { } /// ``` + #[clippy::version = "pre 1.29.0"] pub INEFFECTIVE_BIT_MASK, correctness, "expressions where a bit mask will be rendered useless by a comparison, e.g., `(x | 1) > 2`" @@ -95,6 +97,7 @@ declare_clippy_lint! { /// # let x = 1; /// if x & 0b1111 == 0 { } /// ``` + #[clippy::version = "pre 1.29.0"] pub VERBOSE_BIT_MASK, pedantic, "expressions where a bit mask is less readable than the corresponding method call" diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index 916c78c982a..1600fb25d89 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -17,6 +17,7 @@ declare_clippy_lint! { /// ```rust /// let foo = 3.14; /// ``` + #[clippy::version = "pre 1.29.0"] pub BLACKLISTED_NAME, style, "usage of a blacklisted/placeholder name" diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 47e5b0d583d..b59f49357df 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// let res = { let x = somefunc(); x }; /// if res { /* ... */ } /// ``` + #[clippy::version = "1.45.0"] pub BLOCKS_IN_IF_CONDITIONS, style, "useless or complex blocks that can be eliminated in conditions" diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index cdc192a47e4..a59abc66306 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -23,6 +23,7 @@ declare_clippy_lint! { /// // Good /// assert!(!"a".is_empty()); /// ``` + #[clippy::version = "1.53.0"] pub BOOL_ASSERT_COMPARISON, style, "Using a boolean as comparison value in an assert_* macro when there is no need" diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index a1e6b7224ff..51835ee7488 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// if a && true // should be: if a /// if !(a == b) // should be: if a != b /// ``` + #[clippy::version = "pre 1.29.0"] pub NONMINIMAL_BOOL, complexity, "boolean expressions that can be written more concisely" @@ -52,6 +53,7 @@ declare_clippy_lint! { /// if a && b || a { ... } /// ``` /// The `b` is unnecessary, the expression is equivalent to `if a`. + #[clippy::version = "pre 1.29.0"] pub LOGIC_BUG, correctness, "boolean expressions that contain terminals which can be eliminated" diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index a07cd5e5f4e..a938ada9d2a 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// # let vec = vec![1_u8]; /// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead /// ``` + #[clippy::version = "pre 1.29.0"] pub NAIVE_BYTECOUNT, pedantic, "use of naive `.filter(|&x| x == y).count()` to count byte values" diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index ff619c59b6e..23f79fdc682 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -42,6 +42,7 @@ declare_clippy_lint! { /// keywords = ["clippy", "lint", "plugin"] /// categories = ["development-tools", "development-tools::cargo-plugins"] /// ``` + #[clippy::version = "1.32.0"] pub CARGO_COMMON_METADATA, cargo, "common metadata is defined in `Cargo.toml`" diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index c876553c165..3f286dd9e2f 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// filename.rsplit('.').next().map(|ext| ext.eq_ignore_ascii_case("rs")) == Some(true) /// } /// ``` + #[clippy::version = "1.51.0"] pub CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS, pedantic, "Checks for calls to ends_with with case-sensitive file extensions" diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index 233abd17894..c674327486c 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { /// let x = u64::MAX; /// x as f64; /// ``` + #[clippy::version = "pre 1.29.0"] pub CAST_PRECISION_LOSS, pedantic, "casts that cause loss of precision, e.g., `x as f32` where `x: u64`" @@ -61,6 +62,7 @@ declare_clippy_lint! { /// let y: i8 = -1; /// y as u128; // will return 18446744073709551615 /// ``` + #[clippy::version = "pre 1.29.0"] pub CAST_SIGN_LOSS, pedantic, "casts from signed types to unsigned types, e.g., `x as u32` where `x: i32`" @@ -83,6 +85,7 @@ declare_clippy_lint! { /// x as u8 /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub CAST_POSSIBLE_TRUNCATION, pedantic, "casts that may cause truncation of the value, e.g., `x as u8` where `x: u32`, or `x as i32` where `x: f32`" @@ -106,6 +109,7 @@ declare_clippy_lint! { /// ```rust /// u32::MAX as i32; // will yield a value of `-1` /// ``` + #[clippy::version = "pre 1.29.0"] pub CAST_POSSIBLE_WRAP, pedantic, "casts that may cause wrapping around the value, e.g., `x as i32` where `x: u32` and `x > i32::MAX`" @@ -138,6 +142,7 @@ declare_clippy_lint! { /// u64::from(x) /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub CAST_LOSSLESS, pedantic, "casts using `as` that are known to be lossless, e.g., `x as u64` where `x: u8`" @@ -163,6 +168,7 @@ declare_clippy_lint! { /// let _ = 2_i32; /// let _ = 0.5_f32; /// ``` + #[clippy::version = "pre 1.29.0"] pub UNNECESSARY_CAST, complexity, "cast to the same type, e.g., `x as i32` where `x: i32`" @@ -190,6 +196,7 @@ declare_clippy_lint! { /// (&1u8 as *const u8).cast::(); /// (&mut 1u8 as *mut u8).cast::(); /// ``` + #[clippy::version = "pre 1.29.0"] pub CAST_PTR_ALIGNMENT, pedantic, "cast from a pointer to a more-strictly-aligned pointer" @@ -217,6 +224,7 @@ declare_clippy_lint! { /// fn fun2() -> i32 { 1 } /// let a = fun2 as usize; /// ``` + #[clippy::version = "pre 1.29.0"] pub FN_TO_NUMERIC_CAST, style, "casting a function pointer to a numeric type other than usize" @@ -247,6 +255,7 @@ declare_clippy_lint! { /// let fn_ptr = fn2 as usize; /// let fn_ptr_truncated = fn_ptr as i32; /// ``` + #[clippy::version = "pre 1.29.0"] pub FN_TO_NUMERIC_CAST_WITH_TRUNCATION, style, "casting a function pointer to a numeric type not wide enough to store the address" @@ -283,6 +292,7 @@ declare_clippy_lint! { /// } /// let _ = fn3 as fn() -> u16; /// ``` + #[clippy::version = "1.58.0"] pub FN_TO_NUMERIC_CAST_ANY, restriction, "casting a function pointer to any integer type" @@ -317,6 +327,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.33.0"] pub CAST_REF_TO_MUT, correctness, "a cast of reference to a mutable pointer" @@ -344,6 +355,7 @@ declare_clippy_lint! { /// ```rust,ignore /// b'x' /// ``` + #[clippy::version = "pre 1.29.0"] pub CHAR_LIT_AS_U8, complexity, "casting a character literal to `u8` truncates" @@ -372,6 +384,7 @@ declare_clippy_lint! { /// let _ = ptr.cast::(); /// let _ = mut_ptr.cast::(); /// ``` + #[clippy::version = "1.51.0"] pub PTR_AS_PTR, pedantic, "casting using `as` from and to raw pointers that doesn't change its mutability, where `pointer::cast` could take the place of `as`" diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 842bbf006cc..ffe6340bd77 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// i32::try_from(foo).is_ok() /// # ; /// ``` + #[clippy::version = "1.37.0"] pub CHECKED_CONVERSIONS, pedantic, "`try_from` could replace manual bounds checking when casting" diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 1ccb8c5d880..84a2373efe1 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// /// ### Example /// No. You'll see it when you get the warning. + #[clippy::version = "1.35.0"] pub COGNITIVE_COMPLEXITY, nursery, "functions that should be split up into multiple functions" diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index 4aa87980715..f03f34e5a4b 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -47,6 +47,7 @@ declare_clippy_lint! { /// … /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub COLLAPSIBLE_IF, style, "nested `if`s that can be collapsed (e.g., `if x { if y { ... } }`" @@ -82,6 +83,7 @@ declare_clippy_lint! { /// … /// } /// ``` + #[clippy::version = "1.51.0"] pub COLLAPSIBLE_ELSE_IF, style, "nested `else`-`if` expressions that can be collapsed (e.g., `else { if x { ... } }`)" diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index a4693fa213b..626f9971f01 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// }; /// } /// ``` + #[clippy::version = "1.50.0"] pub COLLAPSIBLE_MATCH, style, "Nested `match` or `if let` expressions where the patterns may be \"collapsed\" together." diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 597a3c67024..399d11472b0 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -49,6 +49,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.40.0"] pub COMPARISON_CHAIN, style, "`if`s that can be rewritten with `match` and `cmp`" diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index f57da62da5f..d07bc23235b 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// … /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub IFS_SAME_COND, correctness, "consecutive `if`s with the same condition" @@ -88,6 +89,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.41.0"] pub SAME_FUNCTIONS_IN_IF_CONDITION, pedantic, "consecutive `if`s with the same function call" @@ -109,6 +111,7 @@ declare_clippy_lint! { /// 42 /// }; /// ``` + #[clippy::version = "pre 1.29.0"] pub IF_SAME_THEN_ELSE, correctness, "`if` with the same `then` and `else` blocks" @@ -147,6 +150,7 @@ declare_clippy_lint! { /// 42 /// }; /// ``` + #[clippy::version = "1.53.0"] pub BRANCHES_SHARING_CODE, nursery, "`if` statement with shared code in all blocks" diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index c2e9e8b3ab7..026683f6006 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// let a: Vec<_> = my_iterator.take(1).collect(); /// let b: Vec<_> = my_iterator.collect(); /// ``` + #[clippy::version = "1.30.0"] pub COPY_ITERATOR, pedantic, "implementing `Iterator` on a `Copy` type" diff --git a/clippy_lints/src/create_dir.rs b/clippy_lints/src/create_dir.rs index e4ee2772483..6bc4054a5ab 100644 --- a/clippy_lints/src/create_dir.rs +++ b/clippy_lints/src/create_dir.rs @@ -23,6 +23,7 @@ declare_clippy_lint! { /// ```rust /// std::fs::create_dir_all("foo"); /// ``` + #[clippy::version = "1.48.0"] pub CREATE_DIR, restriction, "calling `std::fs::create_dir` instead of `std::fs::create_dir_all`" diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs index bab4a696f83..1aae4c81c73 100644 --- a/clippy_lints/src/dbg_macro.rs +++ b/clippy_lints/src/dbg_macro.rs @@ -23,6 +23,7 @@ declare_clippy_lint! { /// // Good /// true /// ``` + #[clippy::version = "1.34.0"] pub DBG_MACRO, restriction, "`dbg!` macro is intended as a debugging tool" diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 54647ba823e..a0b137efe22 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// // Good /// let s = String::default(); /// ``` + #[clippy::version = "pre 1.29.0"] pub DEFAULT_TRAIT_ACCESS, pedantic, "checks for literal calls to `Default::default()`" @@ -62,6 +63,7 @@ declare_clippy_lint! { /// .. Default::default() /// }; /// ``` + #[clippy::version = "1.49.0"] pub FIELD_REASSIGN_WITH_DEFAULT, style, "binding initialized with Default should have its fields set in the initializer" diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 3f1b7ea6214..3573ea5f026 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -46,6 +46,7 @@ declare_clippy_lint! { /// let i = 10i32; /// let f = 1.23f64; /// ``` + #[clippy::version = "1.52.0"] pub DEFAULT_NUMERIC_FALLBACK, restriction, "usage of unconstrained numeric literals which may cause default numeric fallback." diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 975353add08..bbaae94d3dd 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// ```rust,ignore /// let _ = d.unwrap().deref(); /// ``` + #[clippy::version = "1.44.0"] pub EXPLICIT_DEREF_METHODS, pedantic, "Explicit use of deref or deref_mut method while not in a method chain." diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 01ec306e5e1..d0fab2b48fb 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -46,6 +46,7 @@ declare_clippy_lint! { /// has exactly equal bounds, and therefore this lint is disabled for types with /// generic parameters. /// + #[clippy::version = "1.57.0"] pub DERIVABLE_IMPLS, complexity, "manual implementation of the `Default` trait which is equal to a derive" diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 24ac5917dcb..4b232a26e5d 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -38,6 +38,7 @@ declare_clippy_lint! { /// ... /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub DERIVE_HASH_XOR_EQ, correctness, "deriving `Hash` but implementing `PartialEq` explicitly" @@ -88,6 +89,7 @@ declare_clippy_lint! { /// #[derive(Ord, PartialOrd, PartialEq, Eq)] /// struct Foo; /// ``` + #[clippy::version = "1.47.0"] pub DERIVE_ORD_XOR_PARTIAL_ORD, correctness, "deriving `Ord` but implementing `PartialOrd` explicitly" @@ -114,6 +116,7 @@ declare_clippy_lint! { /// // .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub EXPL_IMPL_CLONE_ON_COPY, pedantic, "implementing `Clone` explicitly on `Copy` types" @@ -147,6 +150,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.45.0"] pub UNSAFE_DERIVE_DESERIALIZE, pedantic, "deriving `serde::Deserialize` on a type that has methods using `unsafe`" diff --git a/clippy_lints/src/disallowed_method.rs b/clippy_lints/src/disallowed_method.rs index 22d726cdcb7..c2217353b32 100644 --- a/clippy_lints/src/disallowed_method.rs +++ b/clippy_lints/src/disallowed_method.rs @@ -47,6 +47,7 @@ declare_clippy_lint! { /// let mut xs = Vec::new(); // Vec::new is _not_ disallowed in the config. /// xs.push(123); // Vec::push is _not_ disallowed in the config. /// ``` + #[clippy::version = "1.49.0"] pub DISALLOWED_METHOD, nursery, "use of a disallowed method call" diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index 6d38d30cd0b..3c3f3631849 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -38,6 +38,7 @@ declare_clippy_lint! { /// let zähler = 10; // OK, it's still latin. /// let カウンタ = 10; // Will spawn the lint. /// ``` + #[clippy::version = "1.55.0"] pub DISALLOWED_SCRIPT_IDENTS, restriction, "usage of non-allowed Unicode scripts" diff --git a/clippy_lints/src/disallowed_type.rs b/clippy_lints/src/disallowed_type.rs index 48f781516f4..7e784ca2244 100644 --- a/clippy_lints/src/disallowed_type.rs +++ b/clippy_lints/src/disallowed_type.rs @@ -42,6 +42,7 @@ declare_clippy_lint! { /// // A similar type that is allowed by the config /// use std::collections::HashMap; /// ``` + #[clippy::version = "1.55.0"] pub DISALLOWED_TYPE, nursery, "use of a disallowed type" diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 87ad5178ff0..249cf260309 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -67,6 +67,7 @@ declare_clippy_lint! { /// /// [SmallVec]: SmallVec /// fn main() {} /// ``` + #[clippy::version = "pre 1.29.0"] pub DOC_MARKDOWN, pedantic, "presence of `_`, `::` or camel-case outside backticks in documentation" @@ -101,6 +102,7 @@ declare_clippy_lint! { /// unimplemented!(); /// } /// ``` + #[clippy::version = "1.39.0"] pub MISSING_SAFETY_DOC, style, "`pub unsafe fn` without `# Safety` docs" @@ -129,6 +131,7 @@ declare_clippy_lint! { /// unimplemented!(); /// } /// ``` + #[clippy::version = "1.41.0"] pub MISSING_ERRORS_DOC, pedantic, "`pub fn` returns `Result` without `# Errors` in doc comment" @@ -159,6 +162,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.52.0"] pub MISSING_PANICS_DOC, pedantic, "`pub fn` may panic without `# Panics` in doc comment" @@ -187,6 +191,7 @@ declare_clippy_lint! { /// unimplemented!(); /// } /// `````` + #[clippy::version = "1.40.0"] pub NEEDLESS_DOCTEST_MAIN, style, "presence of `fn main() {` in code examples" diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 6520bb91faf..176092e5b28 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// # let y = 2; /// if x <= y {} /// ``` + #[clippy::version = "pre 1.29.0"] pub DOUBLE_COMPARISONS, complexity, "unnecessary double comparisons that can be simplified" diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index d0d87b6df9a..e10f740d24a 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// // Good /// foo(0); /// ``` + #[clippy::version = "pre 1.29.0"] pub DOUBLE_PARENS, complexity, "Warn on unnecessary double parentheses" diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 0f3dc866afb..a8f8e3d8a42 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -25,6 +25,7 @@ declare_clippy_lint! { /// // still locked /// operation_that_requires_mutex_to_be_unlocked(); /// ``` + #[clippy::version = "pre 1.29.0"] pub DROP_REF, correctness, "calls to `std::mem::drop` with a reference instead of an owned value" @@ -46,6 +47,7 @@ declare_clippy_lint! { /// let x = Box::new(1); /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped /// ``` + #[clippy::version = "pre 1.29.0"] pub FORGET_REF, correctness, "calls to `std::mem::forget` with a reference instead of an owned value" @@ -67,6 +69,7 @@ declare_clippy_lint! { /// std::mem::drop(x) // A copy of x is passed to the function, leaving the /// // original unaffected /// ``` + #[clippy::version = "pre 1.29.0"] pub DROP_COPY, correctness, "calls to `std::mem::drop` with a value that implements Copy" @@ -94,6 +97,7 @@ declare_clippy_lint! { /// std::mem::forget(x) // A copy of x is passed to the function, leaving the /// // original unaffected /// ``` + #[clippy::version = "pre 1.29.0"] pub FORGET_COPY, correctness, "calls to `std::mem::forget` with a value that implements Copy" diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 3774de62521..3070d105014 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// let _micros = dur.subsec_micros(); /// let _millis = dur.subsec_millis(); /// ``` + #[clippy::version = "pre 1.29.0"] pub DURATION_SUBSEC, complexity, "checks for calculation of subsecond microseconds or milliseconds" diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index b64246515f3..92c56c762aa 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { /// // We don't care about zero. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub ELSE_IF_WITHOUT_ELSE, restriction, "`if` expression with an `else if`, but without a final `else` branch" diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 3453c2da278..af9e65e6361 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// /// struct Test(!); /// ``` + #[clippy::version = "pre 1.29.0"] pub EMPTY_ENUM, pedantic, "enum with no variants" diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 57fd24bd4f0..3d92eb16870 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -54,6 +54,7 @@ declare_clippy_lint! { /// # let v = 1; /// map.entry(k).or_insert(v); /// ``` + #[clippy::version = "pre 1.29.0"] pub MAP_ENTRY, perf, "use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`" diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index a2c3c7a7b49..3b6661c817b 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// Y = 0, /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub ENUM_CLIKE_UNPORTABLE_VARIANT, correctness, "C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`" diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 404b67c8f29..fc3a35efaf8 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// Battenberg, /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub ENUM_VARIANT_NAMES, style, "enums where all variants share a prefix/postfix" @@ -59,6 +60,7 @@ declare_clippy_lint! { /// struct BlackForest; /// } /// ``` + #[clippy::version = "1.33.0"] pub MODULE_NAME_REPETITIONS, pedantic, "type names prefixed/postfixed with their containing module's name" @@ -89,6 +91,7 @@ declare_clippy_lint! { /// ... /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MODULE_INCEPTION, style, "modules that have the same name as their parent module" diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index c034c849b55..10123460527 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// # let b = 4; /// assert_eq!(a, a); /// ``` + #[clippy::version = "pre 1.29.0"] pub EQ_OP, correctness, "equal operands on both sides of a comparison or bitwise combination (e.g., `x == x`)" @@ -59,6 +60,7 @@ declare_clippy_lint! { /// // Good /// x == *y /// ``` + #[clippy::version = "pre 1.29.0"] pub OP_REF, style, "taking a reference to satisfy the type constraints on `==`" diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index e8b1d6f6eda..8905cc0de45 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// do_thing(); /// } /// ``` + #[clippy::version = "1.57.0"] pub EQUATABLE_IF_LET, nursery, "using pattern matching instead of equality" diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index d0944c37cf5..d49cec26be5 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -21,6 +21,7 @@ declare_clippy_lint! { /// 0 * x; /// x & 0; /// ``` + #[clippy::version = "pre 1.29.0"] pub ERASING_OP, correctness, "using erasing operations, e.g., `x * 0` or `y & 0`" diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 75b1c882c23..bc5d2f6278d 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// foo(x); /// println!("{}", x); /// ``` + #[clippy::version = "pre 1.29.0"] pub BOXED_LOCAL, perf, "using `Box` where unnecessary" diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 8def6529b3b..5a4b4247104 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// ``` /// where `foo(_)` is a plain function that takes the exact argument type of /// `x`. + #[clippy::version = "pre 1.29.0"] pub REDUNDANT_CLOSURE, style, "redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)" @@ -60,6 +61,7 @@ declare_clippy_lint! { /// ```rust,ignore /// Some('a').map(char::to_uppercase); /// ``` + #[clippy::version = "1.35.0"] pub REDUNDANT_CLOSURE_FOR_METHOD_CALLS, pedantic, "redundant closures for method calls" diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 1b56dd4b081..cdac9f3e6e1 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { /// }; /// let a = tmp + x; /// ``` + #[clippy::version = "pre 1.29.0"] pub EVAL_ORDER_DEPENDENCE, suspicious, "whether a variable read occurs before a write depends on sub-expression evaluation order" @@ -67,6 +68,7 @@ declare_clippy_lint! { /// let x = (a, b, c, panic!()); /// // can simply be replaced by `panic!()` /// ``` + #[clippy::version = "pre 1.29.0"] pub DIVERGING_SUB_EXPRESSION, complexity, "whether an expression contains a diverging sub expression" diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 06171702f75..5435e15de7b 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -37,6 +37,7 @@ declare_clippy_lint! { /// Finished, /// } /// ``` + #[clippy::version = "1.43.0"] pub STRUCT_EXCESSIVE_BOOLS, pedantic, "using too many bools in a struct" @@ -75,6 +76,7 @@ declare_clippy_lint! { /// /// fn f(shape: Shape, temperature: Temperature) { ... } /// ``` + #[clippy::version = "1.43.0"] pub FN_PARAMS_EXCESSIVE_BOOLS, pedantic, "using too many bools in function parameters" diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index bb4684ce38b..b0f50b5c144 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// Baz /// } /// ``` + #[clippy::version = "1.51.0"] pub EXHAUSTIVE_ENUMS, restriction, "detects exported enums that have not been marked #[non_exhaustive]" @@ -60,6 +61,7 @@ declare_clippy_lint! { /// baz: String, /// } /// ``` + #[clippy::version = "1.51.0"] pub EXHAUSTIVE_STRUCTS, restriction, "detects exported structs that have not been marked #[non_exhaustive]" diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 9cd5b2d9f44..d64cc61916c 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -18,6 +18,7 @@ declare_clippy_lint! { /// ```ignore /// std::process::exit(0) /// ``` + #[clippy::version = "1.41.0"] pub EXIT, restriction, "`std::process::exit` is called, terminating the program" diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 4f46ef906f4..6b327b9ce17 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -23,6 +23,7 @@ declare_clippy_lint! { /// // this would be clearer as `eprintln!("foo: {:?}", bar);` /// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap(); /// ``` + #[clippy::version = "pre 1.29.0"] pub EXPLICIT_WRITE, complexity, "using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work" diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 70337f5bbeb..05d300058cf 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -44,6 +44,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub FALLIBLE_IMPL_FROM, nursery, "Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`" diff --git a/clippy_lints/src/feature_name.rs b/clippy_lints/src/feature_name.rs index f534327f7a0..dc6bef52ddd 100644 --- a/clippy_lints/src/feature_name.rs +++ b/clippy_lints/src/feature_name.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// ghi = [] /// ``` /// + #[clippy::version = "1.57.0"] pub REDUNDANT_FEATURE_NAMES, cargo, "usage of a redundant feature name" @@ -60,6 +61,7 @@ declare_clippy_lint! { /// def = [] /// /// ``` + #[clippy::version = "1.57.0"] pub NEGATIVE_FEATURE_NAMES, cargo, "usage of a negative feature name" diff --git a/clippy_lints/src/float_equality_without_abs.rs b/clippy_lints/src/float_equality_without_abs.rs index c33d80b8e8e..ca8886228de 100644 --- a/clippy_lints/src/float_equality_without_abs.rs +++ b/clippy_lints/src/float_equality_without_abs.rs @@ -37,6 +37,7 @@ declare_clippy_lint! { /// (a - b).abs() < f32::EPSILON /// } /// ``` + #[clippy::version = "1.48.0"] pub FLOAT_EQUALITY_WITHOUT_ABS, suspicious, "float equality check without `.abs()`" diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 1e8a5bd7d34..d30dede833c 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// let v: f64 = 0.123_456_789_9; /// println!("{}", v); // 0.123_456_789_9 /// ``` + #[clippy::version = "pre 1.29.0"] pub EXCESSIVE_PRECISION, style, "excessive precision for float literal" @@ -50,6 +51,7 @@ declare_clippy_lint! { /// let _: f32 = 16_777_216.0; /// let _: f64 = 16_777_217.0; /// ``` + #[clippy::version = "1.43.0"] pub LOSSY_FLOAT_LITERAL, restriction, "lossy whole number float literals" diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index eda611117ba..914723a4802 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -43,6 +43,7 @@ declare_clippy_lint! { /// let _ = a.ln_1p(); /// let _ = a.exp_m1(); /// ``` + #[clippy::version = "1.43.0"] pub IMPRECISE_FLOPS, nursery, "usage of imprecise floating point operations" @@ -99,6 +100,7 @@ declare_clippy_lint! { /// let _ = a.abs(); /// let _ = -a.abs(); /// ``` + #[clippy::version = "1.43.0"] pub SUBOPTIMAL_FLOPS, nursery, "usage of sub-optimal floating point operations" diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 7169ac9ad6c..3f043e5f2f1 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// // Good /// foo.to_owned(); /// ``` + #[clippy::version = "pre 1.29.0"] pub USELESS_FORMAT, complexity, "useless use of `format!`" diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index bb30accf145..f0e1a67dcdd 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// # use std::panic::Location; /// println!("error: something failed at {}", Location::caller()); /// ``` + #[clippy::version = "1.58.0"] pub FORMAT_IN_FORMAT_ARGS, perf, "`format!` used in a macro that does formatting" @@ -56,6 +57,7 @@ declare_clippy_lint! { /// # use std::panic::Location; /// println!("error: something failed at {}", Location::caller()); /// ``` + #[clippy::version = "1.58.0"] pub TO_STRING_IN_FORMAT_ARGS, perf, "`to_string` applied to a type that implements `Display` in format args" diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index b4f186525c5..3e85c8a9c80 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -21,6 +21,7 @@ declare_clippy_lint! { /// ```rust,ignore /// a =- 42; // confusing, should it be `a -= 42` or `a = -42`? /// ``` + #[clippy::version = "pre 1.29.0"] pub SUSPICIOUS_ASSIGNMENT_FORMATTING, suspicious, "suspicious formatting of `*=`, `-=` or `!=`" @@ -43,6 +44,7 @@ declare_clippy_lint! { /// if foo &&! bar { // this should be `foo && !bar` but looks like a different operator /// } /// ``` + #[clippy::version = "1.40.0"] pub SUSPICIOUS_UNARY_OP_FORMATTING, suspicious, "suspicious formatting of unary `-` or `!` on the RHS of a BinOp" @@ -79,6 +81,7 @@ declare_clippy_lint! { /// if bar { // this is the `else` block of the previous `if`, but should it be? /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub SUSPICIOUS_ELSE_FORMATTING, suspicious, "suspicious formatting of `else`" @@ -99,6 +102,7 @@ declare_clippy_lint! { /// -4, -5, -6 /// ]; /// ``` + #[clippy::version = "pre 1.29.0"] pub POSSIBLE_MISSING_COMMA, correctness, "possible missing comma in array" diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 347c6eb12cb..866ff216f84 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.51.0"] pub FROM_OVER_INTO, style, "Warns on implementations of `Into<..>` to use `From<..>`" diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index 98ce3db025c..73e800073b0 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// let input: &str = get_input(); /// let num: u16 = input.parse()?; /// ``` + #[clippy::version = "1.52.0"] pub FROM_STR_RADIX_10, style, "from_str_radix with radix 10" diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index d7c5ec9ba35..ad031cbc09d 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// // .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub TOO_MANY_ARGUMENTS, complexity, "functions with too many arguments" @@ -49,6 +50,7 @@ declare_clippy_lint! { /// println!(""); /// } /// ``` + #[clippy::version = "1.34.0"] pub TOO_MANY_LINES, pedantic, "functions with too many lines" @@ -84,6 +86,7 @@ declare_clippy_lint! { /// println!("{}", unsafe { *x }); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NOT_UNSAFE_PTR_ARG_DEREF, correctness, "public functions dereferencing raw pointer arguments but not marked `unsafe`" @@ -103,6 +106,7 @@ declare_clippy_lint! { /// #[must_use] /// fn useless() { } /// ``` + #[clippy::version = "1.40.0"] pub MUST_USE_UNIT, style, "`#[must_use]` attribute on a unit-returning function / method" @@ -126,6 +130,7 @@ declare_clippy_lint! { /// unimplemented!(); /// } /// ``` + #[clippy::version = "1.40.0"] pub DOUBLE_MUST_USE, style, "`#[must_use]` attribute on a `#[must_use]`-returning function / method" @@ -155,6 +160,7 @@ declare_clippy_lint! { /// // this could be annotated with `#[must_use]`. /// fn id(t: T) -> T { t } /// ``` + #[clippy::version = "1.40.0"] pub MUST_USE_CANDIDATE, pedantic, "function or method that could take a `#[must_use]` attribute" @@ -204,6 +210,7 @@ declare_clippy_lint! { /// /// Note that there are crates that simplify creating the error type, e.g. /// [`thiserror`](https://docs.rs/thiserror). + #[clippy::version = "1.49.0"] pub RESULT_UNIT_ERR, style, "public function returning `Result` with an `Err` type of `()`" diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index e18442515b8..03af498eae3 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// ```rust /// async fn is_send(bytes: std::sync::Arc<[u8]>) {} /// ``` + #[clippy::version = "1.44.0"] pub FUTURE_NOT_SEND, nursery, "public Futures must be Send" diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index f3929b0f1e6..edca701869e 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// let x = vec![2, 3, 5]; /// let last_element = x.last(); /// ``` + #[clippy::version = "1.37.0"] pub GET_LAST_WITH_LEN, complexity, "Using `x.get(x.len() - 1)` when `x.last()` is correct and simpler" diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 414f465c494..b4e7bbc7671 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -22,6 +22,7 @@ declare_clippy_lint! { /// # let x = 1; /// x / 1 + 0 * 1 - 0 | 0; /// ``` + #[clippy::version = "pre 1.29.0"] pub IDENTITY_OP, complexity, "using identity operations, e.g., `x + 0` or `y / 1`" diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index a4118bf54b6..e20741d2407 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// use_locked(locked); /// } /// ``` + #[clippy::version = "1.45.0"] pub IF_LET_MUTEX, correctness, "locking a `Mutex` in an `if let` block can cause deadlocks" diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index ac938156237..3d59b783337 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// a() /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub IF_NOT_ELSE, pedantic, "`if` branches that could be swapped so no negation operation is necessary on the condition" diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index a2dac57454f..d95f5d41071 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// 42 /// }); /// ``` + #[clippy::version = "1.53.0"] pub IF_THEN_SOME_ELSE_NONE, restriction, "Finds if-else that could be written using `bool::then`" diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 81eb51e6f7c..6358228dd47 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -54,6 +54,7 @@ declare_clippy_lint! { /// /// pub fn foo(map: &mut HashMap) { } /// ``` + #[clippy::version = "pre 1.29.0"] pub IMPLICIT_HASHER, pedantic, "missing generalization over different hashers" diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 6d7c71d4082..07caeada80d 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// return x; /// } /// ``` + #[clippy::version = "1.33.0"] pub IMPLICIT_RETURN, restriction, "use a return statement like `return expr` instead of an expression" diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index ecbbbc5bc64..4088c54623d 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// // Good /// i = i.saturating_sub(1); /// ``` + #[clippy::version = "1.44.0"] pub IMPLICIT_SATURATING_SUB, pedantic, "Perform saturating subtraction instead of implicitly checking lower bound of data type" diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 52c92b3b122..1debdef9d86 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -55,6 +55,7 @@ declare_clippy_lint! { /// # let y = 2; /// Foo { x, y }; /// ``` + #[clippy::version = "1.52.0"] pub INCONSISTENT_STRUCT_CONSTRUCTOR, pedantic, "the order of the field init shorthand is inconsistent with the order in the struct definition" diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index f52f090d387..9ead4bb27a5 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// x[0]; /// x[3]; /// ``` + #[clippy::version = "pre 1.29.0"] pub OUT_OF_BOUNDS_INDEXING, correctness, "out of bounds constant indexing" @@ -85,6 +86,7 @@ declare_clippy_lint! { /// y.get(10..); /// y.get(..100); /// ``` + #[clippy::version = "pre 1.29.0"] pub INDEXING_SLICING, restriction, "indexing/slicing usage" diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 68c1fa35fcc..c7db47a552b 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// /// iter::repeat(1_u8).collect::>(); /// ``` + #[clippy::version = "pre 1.29.0"] pub INFINITE_ITER, correctness, "infinite iteration" @@ -42,6 +43,7 @@ declare_clippy_lint! { /// let infinite_iter = 0..; /// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5)); /// ``` + #[clippy::version = "pre 1.29.0"] pub MAYBE_INFINITE_ITER, pedantic, "possible infinite iteration" diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index bd0b2964309..254d3f8a4d0 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// fn other() {} /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MULTIPLE_INHERENT_IMPL, restriction, "Multiple inherent impl that could be grouped" diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 61dd0eb4af7..60d234cd6f0 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.38.0"] pub INHERENT_TO_STRING, style, "type implements inherent method `to_string()`, but should instead implement the `Display` trait" @@ -88,6 +89,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.38.0"] pub INHERENT_TO_STRING_SHADOW_DISPLAY, correctness, "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait" diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 3e3df903f17..df69d3dcc51 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -24,6 +24,7 @@ declare_clippy_lint! { /// fn name(&self) -> &'static str; /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub INLINE_FN_WITHOUT_BODY, correctness, "use of `#[inline]` on trait methods without bodies" diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 6850e0c3476..3716d36ad88 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// # let y = 1; /// if x > y {} /// ``` + #[clippy::version = "pre 1.29.0"] pub INT_PLUS_ONE, complexity, "instead of using `x >= y + 1`, use `x > y`" diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs index c962e814fa5..fa786205678 100644 --- a/clippy_lints/src/integer_division.rs +++ b/clippy_lints/src/integer_division.rs @@ -23,6 +23,7 @@ declare_clippy_lint! { /// let x = 3f32 / 2f32; /// println!("{}", x); /// ``` + #[clippy::version = "1.37.0"] pub INTEGER_DIVISION, restriction, "integer division may cause loss of precision" diff --git a/clippy_lints/src/invalid_upcast_comparisons.rs b/clippy_lints/src/invalid_upcast_comparisons.rs index 82438d85c7a..36e03e50a8e 100644 --- a/clippy_lints/src/invalid_upcast_comparisons.rs +++ b/clippy_lints/src/invalid_upcast_comparisons.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// let x: u8 = 1; /// (x as u32) > 300; /// ``` + #[clippy::version = "pre 1.29.0"] pub INVALID_UPCAST_COMPARISONS, pedantic, "a comparison involving an upcast which is always true or false" diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index 3736d237642..b118d3c8b87 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -45,6 +45,7 @@ declare_clippy_lint! { /// foo(); // prints "foo" /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub ITEMS_AFTER_STATEMENTS, pedantic, "blocks where an item comes after a statement" diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index 6c779348ca2..968bbc524b2 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.57.0"] pub ITER_NOT_RETURNING_ITERATOR, pedantic, "methods named `iter` or `iter_mut` that do not return an `Iterator`" diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index fe6814e35d0..80260e4cd83 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// // Good /// pub static a = [0u32; 1_000_000]; /// ``` + #[clippy::version = "1.44.0"] pub LARGE_CONST_ARRAYS, perf, "large non-scalar const array may cause performance overhead" diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 392166237be..0191713f60d 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { /// B(Box<[i32; 8000]>), /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub LARGE_ENUM_VARIANT, perf, "large size difference between variants on an enum" diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index bbb6c1f902c..1cc2c28c04a 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -19,6 +19,7 @@ declare_clippy_lint! { /// ```rust,ignore /// let a = [0u32; 1_000_000]; /// ``` + #[clippy::version = "1.41.0"] pub LARGE_STACK_ARRAYS, pedantic, "allocating large arrays on stack may cause stack overflow" diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index f336fb9d42f..09cd0d22d8b 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -46,6 +46,7 @@ declare_clippy_lint! { /// .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub LEN_ZERO, style, "checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` could be used instead" @@ -71,6 +72,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub LEN_WITHOUT_IS_EMPTY, style, "traits or impls with a public `len` method but no corresponding `is_empty` method" @@ -108,6 +110,7 @@ declare_clippy_lint! { /// .. /// } /// ``` + #[clippy::version = "1.49.0"] pub COMPARISON_TO_EMPTY, style, "checking `x == \"\"` or `x == []` (or similar) when `.is_empty()` could be used instead" diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 7f2c7b707f0..db09d00d730 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -48,6 +48,7 @@ declare_clippy_lint! { /// None /// }; /// ``` + #[clippy::version = "pre 1.29.0"] pub USELESS_LET_IF_SEQ, nursery, "unidiomatic `let mut` declaration followed by initialization in `if`" diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 9efd7aba7e8..557051fb8d2 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// // is_ok() is marked #[must_use] /// let _ = f().is_ok(); /// ``` + #[clippy::version = "1.42.0"] pub LET_UNDERSCORE_MUST_USE, restriction, "non-binding let on a `#[must_use]` expression" @@ -53,6 +54,7 @@ declare_clippy_lint! { /// ```rust,ignore /// let _lock = mutex.lock(); /// ``` + #[clippy::version = "1.43.0"] pub LET_UNDERSCORE_LOCK, correctness, "non-binding let on a synchronization lock" @@ -94,6 +96,7 @@ declare_clippy_lint! { /// // dropped at end of scope /// } /// ``` + #[clippy::version = "1.50.0"] pub LET_UNDERSCORE_DROP, pedantic, "non-binding let on a type that implements `Drop`" diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 6565d5a6d70..fad3343d128 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -45,6 +45,7 @@ declare_clippy_lint! { /// x /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_LIFETIMES, complexity, "using explicit lifetimes for references in function arguments when elision rules \ @@ -73,6 +74,7 @@ declare_clippy_lint! { /// // ... /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub EXTRA_UNUSED_LIFETIMES, complexity, "unused lifetimes in function definitions" diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 0e36ab085a3..130543bbbee 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// // Good /// let x: u64 = 61_864_918_973_511; /// ``` + #[clippy::version = "pre 1.29.0"] pub UNREADABLE_LITERAL, pedantic, "long literal without underscores" @@ -53,6 +54,7 @@ declare_clippy_lint! { /// // Good /// 2_i32; /// ``` + #[clippy::version = "1.30.0"] pub MISTYPED_LITERAL_SUFFIXES, correctness, "mistyped literal suffix" @@ -75,6 +77,7 @@ declare_clippy_lint! { /// // Good /// let x: u64 = 61_864_918_973_511; /// ``` + #[clippy::version = "pre 1.29.0"] pub INCONSISTENT_DIGIT_GROUPING, style, "integer literals with digits grouped inconsistently" @@ -93,6 +96,7 @@ declare_clippy_lint! { /// let x: u32 = 0xFFF_FFF; /// let y: u8 = 0b01_011_101; /// ``` + #[clippy::version = "1.49.0"] pub UNUSUAL_BYTE_GROUPINGS, style, "binary or hex literals that aren't grouped by four" @@ -111,6 +115,7 @@ declare_clippy_lint! { /// ```rust /// let x: u64 = 6186491_8973511; /// ``` + #[clippy::version = "pre 1.29.0"] pub LARGE_DIGIT_GROUPS, pedantic, "grouping digits into groups that are too large" @@ -128,6 +133,7 @@ declare_clippy_lint! { /// `255` => `0xFF` /// `65_535` => `0xFFFF` /// `4_042_322_160` => `0xF0F0_F0F0` + #[clippy::version = "pre 1.29.0"] pub DECIMAL_LITERAL_REPRESENTATION, restriction, "using decimal representation when hexadecimal would be better" diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 5df1b796401..ccec648fa78 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -47,6 +47,7 @@ declare_clippy_lint! { /// # let mut dst = vec![0; 65]; /// dst[64..(src.len() + 64)].clone_from_slice(&src[..]); /// ``` + #[clippy::version = "pre 1.29.0"] pub MANUAL_MEMCPY, perf, "manually copying items between slices" @@ -75,6 +76,7 @@ declare_clippy_lint! { /// println!("{}", i); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_RANGE_LOOP, style, "for-looping over a range of indices where an iterator over items would do" @@ -107,6 +109,7 @@ declare_clippy_lint! { /// // .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub EXPLICIT_ITER_LOOP, pedantic, "for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do" @@ -135,6 +138,7 @@ declare_clippy_lint! { /// // .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub EXPLICIT_INTO_ITER_LOOP, pedantic, "for-looping over `_.into_iter()` when `_` would do" @@ -158,6 +162,7 @@ declare_clippy_lint! { /// .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub ITER_NEXT_LOOP, correctness, "for-looping over `_.next()` which is probably not intended" @@ -201,6 +206,7 @@ declare_clippy_lint! { /// // .. /// } /// ``` + #[clippy::version = "1.45.0"] pub FOR_LOOPS_OVER_FALLIBLES, suspicious, "for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`" @@ -233,6 +239,7 @@ declare_clippy_lint! { /// // .. do something with x /// }; /// ``` + #[clippy::version = "pre 1.29.0"] pub WHILE_LET_LOOP, complexity, "`loop { if let { ... } else break }`, which can be written as a `while let` loop" @@ -254,6 +261,7 @@ declare_clippy_lint! { /// // should be /// let len = iterator.count(); /// ``` + #[clippy::version = "1.30.0"] pub NEEDLESS_COLLECT, perf, "collecting an iterator when collect is not needed" @@ -284,6 +292,7 @@ declare_clippy_lint! { /// # fn bar(bar: usize, baz: usize) {} /// for (i, item) in v.iter().enumerate() { bar(i, *item); } /// ``` + #[clippy::version = "pre 1.29.0"] pub EXPLICIT_COUNTER_LOOP, complexity, "for-looping with an explicit counter when `_.enumerate()` would do" @@ -317,6 +326,7 @@ declare_clippy_lint! { /// ```no_run /// loop {} /// ``` + #[clippy::version = "pre 1.29.0"] pub EMPTY_LOOP, suspicious, "empty `loop {}`, which should block or sleep" @@ -336,6 +346,7 @@ declare_clippy_lint! { /// .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub WHILE_LET_ON_ITERATOR, style, "using a `while let` loop instead of a for loop on an iterator" @@ -364,6 +375,7 @@ declare_clippy_lint! { /// .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub FOR_KV_MAP, style, "looping on a map using `iter` when `keys` or `values` would do" @@ -385,6 +397,7 @@ declare_clippy_lint! { /// break; /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEVER_LOOP, correctness, "any loop that will always `break` or `return`" @@ -420,6 +433,7 @@ declare_clippy_lint! { /// println!("{}", i); // prints numbers from 0 to 42, not 0 to 21 /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MUT_RANGE_BOUND, suspicious, "for loop over a range where one of the bounds is a mutable variable" @@ -446,6 +460,7 @@ declare_clippy_lint! { /// println!("let me loop forever!"); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub WHILE_IMMUTABLE_CONDITION, correctness, "variables used within while expression are not mutated in the body" @@ -480,6 +495,7 @@ declare_clippy_lint! { /// let mut vec: Vec = vec![item1; 20]; /// vec.resize(20 + 30, item2); /// ``` + #[clippy::version = "1.47.0"] pub SAME_ITEM_PUSH, style, "the same item is pushed inside of a for loop" @@ -506,6 +522,7 @@ declare_clippy_lint! { /// let item = &item1; /// println!("{}", item); /// ``` + #[clippy::version = "1.49.0"] pub SINGLE_ELEMENT_LOOP, complexity, "there is no reason to have a single element loop" @@ -537,6 +554,7 @@ declare_clippy_lint! { /// println!("{}", n); /// } /// ``` + #[clippy::version = "1.52.0"] pub MANUAL_FLATTEN, complexity, "for loops over `Option`s or `Result`s with a single expression can be simplified" diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index bccdc3be5e9..262a26951c6 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -24,6 +24,7 @@ declare_clippy_lint! { /// #[macro_use] /// use some_macro; /// ``` + #[clippy::version = "1.44.0"] pub MACRO_USE_IMPORTS, pedantic, "#[macro_use] is no longer needed" diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 23b3ba2296e..fad8fa467d4 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// main(); /// } /// ``` + #[clippy::version = "1.38.0"] pub MAIN_RECURSION, style, "recursion using the entrypoint" diff --git a/clippy_lints/src/manual_assert.rs b/clippy_lints/src/manual_assert.rs index e55aa3f1850..ed3166086f7 100644 --- a/clippy_lints/src/manual_assert.rs +++ b/clippy_lints/src/manual_assert.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// let sad_people: Vec<&str> = vec![]; /// assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people); /// ``` + #[clippy::version = "1.57.0"] pub MANUAL_ASSERT, pedantic, "`panic!` and only a `panic!` in `if`-then statement" diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index b632af455f8..86819752f90 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// ```rust /// async fn foo() -> i32 { 42 } /// ``` + #[clippy::version = "1.45.0"] pub MANUAL_ASYNC_FN, style, "manual implementations of `async` functions can be simplified using the dedicated syntax" diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index 96df3d0a490..cf5dabd9462 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// ```rust /// Some(0).map(|x| x + 1); /// ``` + #[clippy::version = "1.52.0"] pub MANUAL_MAP, style, "reimplementation of `map`" diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 335ea001ee4..63a72d4fdde 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -52,6 +52,7 @@ declare_clippy_lint! { /// #[non_exhaustive] /// struct T(pub i32, pub i32); /// ``` + #[clippy::version = "1.45.0"] pub MANUAL_NON_EXHAUSTIVE, style, "manual implementations of the non-exhaustive pattern can be simplified using #[non_exhaustive]" diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index cf641d0ce86..b60e2dc366b 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// let foo: Option = None; /// foo.ok_or("error"); /// ``` + #[clippy::version = "1.49.0"] pub MANUAL_OK_OR, pedantic, "finds patterns that can be encoded more concisely with `Option::ok_or`" diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 4e040508b6b..f8e28f1671f 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -42,6 +42,7 @@ declare_clippy_lint! { /// assert_eq!(end.to_uppercase(), "WORLD!"); /// } /// ``` + #[clippy::version = "1.48.0"] pub MANUAL_STRIP, complexity, "suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing" diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 42478e3416e..aac3c6e0de2 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// let foo: Option = None; /// foo.unwrap_or(1); /// ``` + #[clippy::version = "1.49.0"] pub MANUAL_UNWRAP_OR, complexity, "finds patterns that can be encoded more concisely with `Option::unwrap_or` or `Result::unwrap_or`" diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 7db5c7e52ea..c2b78e21861 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -37,6 +37,7 @@ declare_clippy_lint! { /// let y = x.iter(); /// let z = y.cloned(); /// ``` + #[clippy::version = "pre 1.29.0"] pub MAP_CLONE, style, "using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types" diff --git a/clippy_lints/src/map_err_ignore.rs b/clippy_lints/src/map_err_ignore.rs index 82d3732326e..61f21d532c5 100644 --- a/clippy_lints/src/map_err_ignore.rs +++ b/clippy_lints/src/map_err_ignore.rs @@ -97,6 +97,7 @@ declare_clippy_lint! { /// }) /// } /// ``` + #[clippy::version = "1.48.0"] pub MAP_ERR_IGNORE, restriction, "`map_err` should not ignore the original error" diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 40de9ffcd4e..a84de3e079b 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -47,6 +47,7 @@ declare_clippy_lint! { /// log_err_msg(format_msg(msg)); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub OPTION_MAP_UNIT_FN, complexity, "using `option.map(f)`, where `f` is a function or closure that returns `()`" @@ -87,6 +88,7 @@ declare_clippy_lint! { /// log_err_msg(format_msg(msg)); /// }; /// ``` + #[clippy::version = "pre 1.29.0"] pub RESULT_MAP_UNIT_FN, complexity, "using `result.map(f)`, where `f` is a function or closure that returns `()`" diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index 552c9a58897..583b577ffe2 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { /// _ => {}, /// } /// ``` + #[clippy::version = "1.45.0"] pub MATCH_ON_VEC_ITEMS, pedantic, "matching on vector elements can panic" diff --git a/clippy_lints/src/match_result_ok.rs b/clippy_lints/src/match_result_ok.rs index ecf6ad316a4..b1839f00aae 100644 --- a/clippy_lints/src/match_result_ok.rs +++ b/clippy_lints/src/match_result_ok.rs @@ -38,6 +38,7 @@ declare_clippy_lint! { /// vec.push(value) /// } /// ``` + #[clippy::version = "1.57.0"] pub MATCH_RESULT_OK, style, "usage of `ok()` in `let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead" diff --git a/clippy_lints/src/match_str_case_mismatch.rs b/clippy_lints/src/match_str_case_mismatch.rs index f501593c518..3316ebf4051 100644 --- a/clippy_lints/src/match_str_case_mismatch.rs +++ b/clippy_lints/src/match_str_case_mismatch.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// _ => {}, /// } /// ``` + #[clippy::version = "1.58.0"] pub MATCH_STR_CASE_MISMATCH, correctness, "creation of a case altering match expression with non-compliant arms" diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index e4e533fa71a..74765a1a1de 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -57,6 +57,7 @@ declare_clippy_lint! { /// bar(foo); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub SINGLE_MATCH, style, "a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`" @@ -98,6 +99,7 @@ declare_clippy_lint! { /// bar(&other_ref); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub SINGLE_MATCH_ELSE, pedantic, "a `match` statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern" @@ -129,6 +131,7 @@ declare_clippy_lint! { /// _ => frob(x), /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MATCH_REF_PATS, style, "a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression" @@ -163,6 +166,7 @@ declare_clippy_lint! { /// bar(); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MATCH_BOOL, pedantic, "a `match` on a boolean expression instead of an `if..else` block" @@ -185,6 +189,7 @@ declare_clippy_lint! { /// _ => (), /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MATCH_OVERLAPPING_ARM, style, "a `match` with overlapping arms" @@ -207,6 +212,7 @@ declare_clippy_lint! { /// Err(_) => panic!("err"), /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MATCH_WILD_ERR_ARM, pedantic, "a `match` with `Err(_)` arm and take drastic actions" @@ -233,6 +239,7 @@ declare_clippy_lint! { /// // Good /// let r: Option<&()> = x.as_ref(); /// ``` + #[clippy::version = "pre 1.29.0"] pub MATCH_AS_REF, complexity, "a `match` on an Option value instead of using `as_ref()` or `as_mut`" @@ -265,6 +272,7 @@ declare_clippy_lint! { /// Foo::B(_) => {}, /// } /// ``` + #[clippy::version = "1.34.0"] pub WILDCARD_ENUM_MATCH_ARM, restriction, "a wildcard enum match arm using `_`" @@ -299,6 +307,7 @@ declare_clippy_lint! { /// Foo::C => {}, /// } /// ``` + #[clippy::version = "1.45.0"] pub MATCH_WILDCARD_FOR_SINGLE_VARIANTS, pedantic, "a wildcard enum match for a single variant" @@ -326,6 +335,7 @@ declare_clippy_lint! { /// _ => {}, /// } /// ``` + #[clippy::version = "1.42.0"] pub WILDCARD_IN_OR_PATTERNS, complexity, "a wildcard pattern used with others patterns in same match arm" @@ -361,6 +371,7 @@ declare_clippy_lint! { /// let wrapper = Wrapper::Data(42); /// let Wrapper::Data(data) = wrapper; /// ``` + #[clippy::version = "pre 1.29.0"] pub INFALLIBLE_DESTRUCTURING_MATCH, style, "a `match` statement with a single infallible arm instead of a `let`" @@ -392,6 +403,7 @@ declare_clippy_lint! { /// // Good /// let (c, d) = (a, b); /// ``` + #[clippy::version = "1.43.0"] pub MATCH_SINGLE_BINDING, complexity, "a match with a single binding instead of using `let` statement" @@ -422,6 +434,7 @@ declare_clippy_lint! { /// _ => {}, /// } /// ``` + #[clippy::version = "1.43.0"] pub REST_PAT_IN_FULLY_BOUND_STRUCTS, restriction, "a match on a struct that binds all fields but still uses the wildcard pattern" @@ -477,6 +490,7 @@ declare_clippy_lint! { /// if IpAddr::V6(Ipv6Addr::LOCALHOST).is_ipv6() {} /// Ok::(42).is_ok(); /// ``` + #[clippy::version = "1.31.0"] pub REDUNDANT_PATTERN_MATCHING, style, "use the proper utility function avoiding an `if let`" @@ -513,6 +527,7 @@ declare_clippy_lint! { /// // Good /// let a = matches!(x, Some(0)); /// ``` + #[clippy::version = "1.47.0"] pub MATCH_LIKE_MATCHES_MACRO, style, "a match that could be written with the matches! macro" @@ -557,6 +572,7 @@ declare_clippy_lint! { /// Quz => quz(), /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MATCH_SAME_ARMS, pedantic, "`match` with identical arm bodies" diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index eb437dc47af..5ffcfd4d264 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -19,6 +19,7 @@ declare_clippy_lint! { /// # use std::rc::Rc; /// mem::forget(Rc::new(55)) /// ``` + #[clippy::version = "pre 1.29.0"] pub MEM_FORGET, restriction, "`mem::forget` usage on `Drop` types, likely to cause memory leaks" diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index cf721fc65db..7fc39f17232 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// let mut an_option = Some(0); /// let taken = an_option.take(); /// ``` + #[clippy::version = "1.31.0"] pub MEM_REPLACE_OPTION_WITH_NONE, style, "replacing an `Option` with `None` instead of `take()`" @@ -66,6 +67,7 @@ declare_clippy_lint! { /// The [take_mut](https://docs.rs/take_mut) crate offers a sound solution, /// at the cost of either lazily creating a replacement value or aborting /// on panic, to ensure that the uninitialized value cannot be observed. + #[clippy::version = "1.39.0"] pub MEM_REPLACE_WITH_UNINIT, correctness, "`mem::replace(&mut _, mem::uninitialized())` or `mem::replace(&mut _, mem::zeroed())`" @@ -90,6 +92,7 @@ declare_clippy_lint! { /// let mut text = String::from("foo"); /// let taken = std::mem::take(&mut text); /// ``` + #[clippy::version = "1.42.0"] pub MEM_REPLACE_WITH_DEFAULT, style, "replacing a value of type `T` with `T::default()` instead of using `std::mem::take`" diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 6c4272f9e65..5cb849a56bc 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -99,6 +99,7 @@ declare_clippy_lint! { /// ```rust /// [1, 2, 3].iter().copied(); /// ``` + #[clippy::version = "1.53.0"] pub CLONED_INSTEAD_OF_COPIED, pedantic, "used `cloned` where `copied` could be used instead" @@ -121,6 +122,7 @@ declare_clippy_lint! { /// ```rust /// let nums: Vec = ["1", "2", "whee!"].iter().filter_map(|x| x.parse().ok()).collect(); /// ``` + #[clippy::version = "1.53.0"] pub FLAT_MAP_OPTION, pedantic, "used `flat_map` where `filter_map` could be used instead" @@ -166,6 +168,7 @@ declare_clippy_lint! { /// // Good /// res.expect("more helpful message"); /// ``` + #[clippy::version = "1.45.0"] pub UNWRAP_USED, restriction, "using `.unwrap()` on `Result` or `Option`, which should at least get a better message using `expect()`" @@ -208,6 +211,7 @@ declare_clippy_lint! { /// res?; /// # Ok::<(), ()>(()) /// ``` + #[clippy::version = "1.45.0"] pub EXPECT_USED, restriction, "using `.expect()` on `Result` or `Option`, which might be better handled" @@ -237,6 +241,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub SHOULD_IMPLEMENT_TRAIT, style, "defining a method that should be implementing a std trait" @@ -284,6 +289,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub WRONG_SELF_CONVENTION, style, "defining a method named with an established prefix (like \"into_\") that takes `self` with the wrong convention" @@ -310,6 +316,7 @@ declare_clippy_lint! { /// // Good /// x.expect("why did I do this again?"); /// ``` + #[clippy::version = "pre 1.29.0"] pub OK_EXPECT, style, "using `ok().expect()`, which gives worse error messages than calling `expect` directly on the Result" @@ -335,6 +342,7 @@ declare_clippy_lint! { /// // Good /// x.unwrap_or_default(); /// ``` + #[clippy::version = "1.56.0"] pub UNWRAP_OR_ELSE_DEFAULT, style, "using `.unwrap_or_else(Default::default)`, which is more succinctly expressed as `.unwrap_or_default()`" @@ -375,6 +383,7 @@ declare_clippy_lint! { /// // Good /// x.map_or_else(some_function, |a| a + 1); /// ``` + #[clippy::version = "1.45.0"] pub MAP_UNWRAP_OR, pedantic, "using `.map(f).unwrap_or(a)` or `.map(f).unwrap_or_else(func)`, which are more succinctly expressed as `map_or(a, f)` or `map_or_else(a, f)`" @@ -401,6 +410,7 @@ declare_clippy_lint! { /// // Good /// opt.and_then(|a| Some(a + 1)); /// ``` + #[clippy::version = "pre 1.29.0"] pub OPTION_MAP_OR_NONE, style, "using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`" @@ -426,6 +436,7 @@ declare_clippy_lint! { /// # let r: Result = Ok(1); /// assert_eq!(Some(1), r.ok()); /// ``` + #[clippy::version = "1.44.0"] pub RESULT_MAP_OR_INTO_OPTION, style, "using `Result.map_or(None, Some)`, which is more succinctly expressed as `ok()`" @@ -458,6 +469,7 @@ declare_clippy_lint! { /// let _ = res().map(|s| if s.len() == 42 { 10 } else { 20 }); /// let _ = res().map_err(|s| if s.len() == 42 { 10 } else { 20 }); /// ``` + #[clippy::version = "1.45.0"] pub BIND_INSTEAD_OF_MAP, complexity, "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`" @@ -481,6 +493,7 @@ declare_clippy_lint! { /// # let vec = vec![1]; /// vec.iter().find(|x| **x == 0); /// ``` + #[clippy::version = "pre 1.29.0"] pub FILTER_NEXT, complexity, "using `filter(p).next()`, which is more succinctly expressed as `.find(p)`" @@ -504,6 +517,7 @@ declare_clippy_lint! { /// # let vec = vec![1]; /// vec.iter().find(|x| **x != 0); /// ``` + #[clippy::version = "1.42.0"] pub SKIP_WHILE_NEXT, complexity, "using `skip_while(p).next()`, which is more succinctly expressed as `.find(!p)`" @@ -527,6 +541,7 @@ declare_clippy_lint! { /// // Good /// vec.iter().flat_map(|x| x.iter()); /// ``` + #[clippy::version = "1.31.0"] pub MAP_FLATTEN, pedantic, "using combinations of `flatten` and `map` which can usually be written as a single method call" @@ -553,6 +568,7 @@ declare_clippy_lint! { /// ```rust /// (0_i32..10).filter_map(|n| n.checked_add(1)); /// ``` + #[clippy::version = "1.51.0"] pub MANUAL_FILTER_MAP, complexity, "using `_.filter(_).map(_)` in a way that can be written more simply as `filter_map(_)`" @@ -579,6 +595,7 @@ declare_clippy_lint! { /// ```rust /// (0_i32..10).find_map(|n| n.checked_add(1)); /// ``` + #[clippy::version = "1.51.0"] pub MANUAL_FIND_MAP, complexity, "using `_.find(_).map(_)` in a way that can be written more simply as `find_map(_)`" @@ -601,6 +618,7 @@ declare_clippy_lint! { /// ```rust /// (0..3).find_map(|x| if x == 2 { Some(x) } else { None }); /// ``` + #[clippy::version = "1.36.0"] pub FILTER_MAP_NEXT, pedantic, "using combination of `filter_map` and `next` which can usually be written as a single method call" @@ -623,6 +641,7 @@ declare_clippy_lint! { /// # let iter = vec![vec![0]].into_iter(); /// iter.flatten(); /// ``` + #[clippy::version = "1.39.0"] pub FLAT_MAP_IDENTITY, complexity, "call to `flat_map` where `flatten` is sufficient" @@ -652,6 +671,7 @@ declare_clippy_lint! { /// /// let _ = !"hello world".contains("world"); /// ``` + #[clippy::version = "pre 1.29.0"] pub SEARCH_IS_SOME, complexity, "using an iterator or string search followed by `is_some()` or `is_none()`, which is more succinctly expressed as a call to `any()` or `contains()` (with negation in case of `is_none()`)" @@ -676,6 +696,7 @@ declare_clippy_lint! { /// let name = "foo"; /// if name.starts_with('_') {}; /// ``` + #[clippy::version = "pre 1.29.0"] pub CHARS_NEXT_CMP, style, "using `.chars().next()` to check if a string starts with a char" @@ -710,6 +731,7 @@ declare_clippy_lint! { /// # let foo = Some(String::new()); /// foo.unwrap_or_default(); /// ``` + #[clippy::version = "pre 1.29.0"] pub OR_FUN_CALL, perf, "using any `*or` method with a function call, which suggests `*or_else`" @@ -748,6 +770,7 @@ declare_clippy_lint! { /// # let err_msg = "I'm a teapot"; /// foo.unwrap_or_else(|| panic!("Err {}: {}", err_code, err_msg)); /// ``` + #[clippy::version = "pre 1.29.0"] pub EXPECT_FUN_CALL, perf, "using any `expect` method with a function call" @@ -765,6 +788,7 @@ declare_clippy_lint! { /// ```rust /// 42u64.clone(); /// ``` + #[clippy::version = "pre 1.29.0"] pub CLONE_ON_COPY, complexity, "using `clone` on a `Copy` type" @@ -792,6 +816,7 @@ declare_clippy_lint! { /// // Good /// Rc::clone(&x); /// ``` + #[clippy::version = "pre 1.29.0"] pub CLONE_ON_REF_PTR, restriction, "using 'clone' on a ref-counted pointer" @@ -814,6 +839,7 @@ declare_clippy_lint! { /// println!("{:p} {:p}", *y, z); // prints out the same pointer /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub CLONE_DOUBLE_REF, correctness, "using `clone` on `&&T`" @@ -837,6 +863,7 @@ declare_clippy_lint! { /// // OK, the specialized impl is used /// ["foo", "bar"].iter().map(|&s| s.to_string()); /// ``` + #[clippy::version = "1.40.0"] pub INEFFICIENT_TO_STRING, pedantic, "using `to_string` on `&&T` where `T: ToString`" @@ -898,6 +925,7 @@ declare_clippy_lint! { /// fn new() -> Self; /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEW_RET_NO_SELF, style, "not returning type containing `Self` in a `new` method" @@ -922,6 +950,7 @@ declare_clippy_lint! { /// /// // Good /// _.split('x'); + #[clippy::version = "pre 1.29.0"] pub SINGLE_CHAR_PATTERN, perf, "using a single-character str where a char could be used, e.g., `_.split(\"x\")`" @@ -941,6 +970,7 @@ declare_clippy_lint! { /// //.. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub ITERATOR_STEP_BY_ZERO, correctness, "using `Iterator::step_by(0)`, which will panic at runtime" @@ -962,6 +992,7 @@ declare_clippy_lint! { /// ```rust /// let _ = std::iter::empty::>().flatten(); /// ``` + #[clippy::version = "1.53.0"] pub OPTION_FILTER_MAP, complexity, "filtering `Option` for `Some` then force-unwrapping, which can be one type-safe operation" @@ -989,6 +1020,7 @@ declare_clippy_lint! { /// # s.insert(1); /// let x = s.iter().next(); /// ``` + #[clippy::version = "1.42.0"] pub ITER_NTH_ZERO, style, "replace `iter.nth(0)` with `iter.next()`" @@ -1015,6 +1047,7 @@ declare_clippy_lint! { /// let bad_vec = some_vec.get(3); /// let bad_slice = &some_vec[..].get(3); /// ``` + #[clippy::version = "pre 1.29.0"] pub ITER_NTH, perf, "using `.iter().nth()` on a standard library type with O(1) element access" @@ -1039,6 +1072,7 @@ declare_clippy_lint! { /// let bad_vec = some_vec.iter().nth(3); /// let bad_slice = &some_vec[..].iter().nth(3); /// ``` + #[clippy::version = "pre 1.29.0"] pub ITER_SKIP_NEXT, style, "using `.skip(x).next()` on an iterator" @@ -1075,6 +1109,7 @@ declare_clippy_lint! { /// let last = some_vec[3]; /// some_vec[0] = 1; /// ``` + #[clippy::version = "pre 1.29.0"] pub GET_UNWRAP, restriction, "using `.get().unwrap()` or `.get_mut().unwrap()` when using `[]` would work instead" @@ -1098,6 +1133,7 @@ declare_clippy_lint! { /// // Good /// a.append(&mut b); /// ``` + #[clippy::version = "1.55.0"] pub EXTEND_WITH_DRAIN, perf, "using vec.append(&mut vec) to move the full range of a vecor to another" @@ -1127,6 +1163,7 @@ declare_clippy_lint! { /// s.push_str(abc); /// s.push_str(&def); /// ``` + #[clippy::version = "pre 1.29.0"] pub STRING_EXTEND_CHARS, style, "using `x.extend(s.chars())` where s is a `&str` or `String`" @@ -1150,6 +1187,7 @@ declare_clippy_lint! { /// let s = [1, 2, 3, 4, 5]; /// let s2: Vec = s.to_vec(); /// ``` + #[clippy::version = "pre 1.29.0"] pub ITER_CLONED_COLLECT, style, "using `.cloned().collect()` on slice to create a `Vec`" @@ -1174,6 +1212,7 @@ declare_clippy_lint! { /// // Good /// name.ends_with('_') || name.ends_with('-'); /// ``` + #[clippy::version = "pre 1.29.0"] pub CHARS_LAST_CMP, style, "using `.chars().last()` or `.chars().next_back()` to check if a string ends with a char" @@ -1199,6 +1238,7 @@ declare_clippy_lint! { /// let x: &[i32] = &[1, 2, 3, 4, 5]; /// do_stuff(x); /// ``` + #[clippy::version = "pre 1.29.0"] pub USELESS_ASREF, complexity, "using `as_ref` where the types before and after the call are the same" @@ -1221,6 +1261,7 @@ declare_clippy_lint! { /// ```rust /// let _ = (0..3).any(|x| x > 2); /// ``` + #[clippy::version = "pre 1.29.0"] pub UNNECESSARY_FOLD, style, "using `fold` when a more succinct alternative exists" @@ -1250,6 +1291,7 @@ declare_clippy_lint! { /// // As there is no conditional check on the argument this could be written as: /// let _ = (0..4).map(|x| x + 1); /// ``` + #[clippy::version = "1.31.0"] pub UNNECESSARY_FILTER_MAP, complexity, "using `filter_map` when a more succinct alternative exists" @@ -1273,6 +1315,7 @@ declare_clippy_lint! { /// // Good /// let _ = (&vec![3, 4, 5]).iter(); /// ``` + #[clippy::version = "1.32.0"] pub INTO_ITER_ON_REF, style, "using `.into_iter()` on a reference" @@ -1292,6 +1335,7 @@ declare_clippy_lint! { /// ```rust /// let _ = (0..3).map(|x| x + 2).count(); /// ``` + #[clippy::version = "1.39.0"] pub SUSPICIOUS_MAP, suspicious, "suspicious usage of map" @@ -1326,6 +1370,7 @@ declare_clippy_lint! { /// MaybeUninit::uninit().assume_init() /// }; /// ``` + #[clippy::version = "1.39.0"] pub UNINIT_ASSUMED_INIT, correctness, "`MaybeUninit::uninit().assume_init()`" @@ -1354,6 +1399,7 @@ declare_clippy_lint! { /// let add = x.saturating_add(y); /// let sub = x.saturating_sub(y); /// ``` + #[clippy::version = "1.39.0"] pub MANUAL_SATURATING_ARITHMETIC, style, "`.chcked_add/sub(x).unwrap_or(MAX/MIN)`" @@ -1371,6 +1417,7 @@ declare_clippy_lint! { /// ```rust /// unsafe { (&() as *const ()).offset(1) }; /// ``` + #[clippy::version = "1.41.0"] pub ZST_OFFSET, correctness, "Check for offset calculations on raw pointers to zero-sized types" @@ -1412,6 +1459,7 @@ declare_clippy_lint! { /// # Ok::<_, std::io::Error>(()) /// # }; /// ``` + #[clippy::version = "1.42.0"] pub FILETYPE_IS_FILE, restriction, "`FileType::is_file` is not recommended to test for readable file type" @@ -1437,6 +1485,7 @@ declare_clippy_lint! { /// opt.as_deref() /// # ; /// ``` + #[clippy::version = "1.42.0"] pub OPTION_AS_REF_DEREF, complexity, "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`" @@ -1463,6 +1512,7 @@ declare_clippy_lint! { /// a.get(2); /// b.get(0); /// ``` + #[clippy::version = "1.46.0"] pub ITER_NEXT_SLICE, style, "using `.iter().next()` on a sliced array, which can be shortened to just `.get()`" @@ -1488,6 +1538,7 @@ declare_clippy_lint! { /// string.insert(0, 'R'); /// string.push('R'); /// ``` + #[clippy::version = "1.49.0"] pub SINGLE_CHAR_ADD_STR, style, "`push_str()` or `insert_str()` used with a single-character string literal as parameter" @@ -1526,6 +1577,7 @@ declare_clippy_lint! { /// /// opt.unwrap_or(42); /// ``` + #[clippy::version = "1.48.0"] pub UNNECESSARY_LAZY_EVALUATIONS, style, "using unnecessary lazy evaluation, which can be replaced with simpler eager evaluation" @@ -1546,6 +1598,7 @@ declare_clippy_lint! { /// ```rust /// (0..3).try_for_each(|t| Err(t)); /// ``` + #[clippy::version = "1.49.0"] pub MAP_COLLECT_RESULT_UNIT, style, "using `.map(_).collect::()`, which can be replaced with `try_for_each`" @@ -1578,6 +1631,7 @@ declare_clippy_lint! { /// /// assert_eq!(v, vec![5, 5, 5, 5, 5]); /// ``` + #[clippy::version = "1.49.0"] pub FROM_ITER_INSTEAD_OF_COLLECT, pedantic, "use `.collect()` instead of `::from_iter()`" @@ -1607,6 +1661,7 @@ declare_clippy_lint! { /// assert!(x >= 0); /// }); /// ``` + #[clippy::version = "1.51.0"] pub INSPECT_FOR_EACH, complexity, "using `.inspect().for_each()`, which can be replaced with `.for_each()`" @@ -1629,6 +1684,7 @@ declare_clippy_lint! { /// # let iter = vec![Some(1)].into_iter(); /// iter.flatten(); /// ``` + #[clippy::version = "1.52.0"] pub FILTER_MAP_IDENTITY, complexity, "call to `filter_map` where `flatten` is sufficient" @@ -1651,6 +1707,7 @@ declare_clippy_lint! { /// let x = [1, 2, 3]; /// let y: Vec<_> = x.iter().map(|x| 2*x).collect(); /// ``` + #[clippy::version = "1.52.0"] pub MAP_IDENTITY, complexity, "using iterator.map(|x| x)" @@ -1672,6 +1729,7 @@ declare_clippy_lint! { /// // Good /// let _ = "Hello".as_bytes().get(3); /// ``` + #[clippy::version = "1.52.0"] pub BYTES_NTH, style, "replace `.bytes().nth()` with `.as_bytes().get()`" @@ -1697,6 +1755,7 @@ declare_clippy_lint! { /// let b = a.clone(); /// let c = a.clone(); /// ``` + #[clippy::version = "1.52.0"] pub IMPLICIT_CLONE, pedantic, "implicitly cloning a value by invoking a function on its dereferenced type" @@ -1722,6 +1781,7 @@ declare_clippy_lint! { /// let _ = some_vec.len(); /// let _ = &some_vec[..].len(); /// ``` + #[clippy::version = "1.52.0"] pub ITER_COUNT, complexity, "replace `.iter().count()` with `.len()`" @@ -1751,6 +1811,7 @@ declare_clippy_lint! { /// // use x /// } /// ``` + #[clippy::version = "1.54.0"] pub SUSPICIOUS_SPLITN, correctness, "checks for `.splitn(0, ..)` and `.splitn(1, ..)`" @@ -1771,6 +1832,7 @@ declare_clippy_lint! { /// // Good /// let x: String = "x".repeat(10); /// ``` + #[clippy::version = "1.54.0"] pub MANUAL_STR_REPEAT, perf, "manual implementation of `str::repeat`" @@ -1793,6 +1855,7 @@ declare_clippy_lint! { /// let (key, value) = _.split_once('=')?; /// let value = _.split_once('=')?.1; /// ``` + #[clippy::version = "1.57.0"] pub MANUAL_SPLIT_ONCE, complexity, "replace `.splitn(2, pat)` with `.split_once(pat)`" diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index dc2dd45e4ed..a6450aec4f7 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// ``` /// It will always be equal to `0`. Probably the author meant to clamp the value /// between 0 and 100, but has erroneously swapped `min` and `max`. + #[clippy::version = "pre 1.29.0"] pub MIN_MAX, correctness, "`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant" diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 0f32cd9164e..a93537104bf 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -56,6 +56,7 @@ declare_clippy_lint! { /// true /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub TOPLEVEL_REF_ARG, style, "an entire binding declared as `ref`, in a function argument or a `let` statement" @@ -79,6 +80,7 @@ declare_clippy_lint! { /// // Good /// if x.is_nan() { } /// ``` + #[clippy::version = "pre 1.29.0"] pub CMP_NAN, correctness, "comparisons to `NAN`, which will always return false, probably not intended" @@ -112,6 +114,7 @@ declare_clippy_lint! { /// if (y - 1.23f64).abs() < error_margin { } /// if (y - x).abs() > error_margin { } /// ``` + #[clippy::version = "pre 1.29.0"] pub FLOAT_CMP, pedantic, "using `==` or `!=` on float values instead of comparing difference with an epsilon" @@ -139,6 +142,7 @@ declare_clippy_lint! { /// # let y = String::from("foo"); /// if x == y {} /// ``` + #[clippy::version = "pre 1.29.0"] pub CMP_OWNED, perf, "creating owned instances for comparing with others, e.g., `x == \"foo\".to_string()`" @@ -162,6 +166,7 @@ declare_clippy_lint! { /// let a = x % 1; /// let a = x % -1; /// ``` + #[clippy::version = "pre 1.29.0"] pub MODULO_ONE, correctness, "taking a number modulo +/-1, which can either panic/overflow or always returns 0" @@ -187,6 +192,7 @@ declare_clippy_lint! { /// let y = _x + 1; // Here we are using `_x`, even though it has a leading /// // underscore. We should rename `_x` to `x` /// ``` + #[clippy::version = "pre 1.29.0"] pub USED_UNDERSCORE_BINDING, pedantic, "using a binding which is prefixed with an underscore" @@ -207,6 +213,7 @@ declare_clippy_lint! { /// ```rust,ignore /// f() && g(); // We should write `if f() { g(); }`. /// ``` + #[clippy::version = "pre 1.29.0"] pub SHORT_CIRCUIT_STATEMENT, complexity, "using a short circuit boolean condition as a statement" @@ -228,6 +235,7 @@ declare_clippy_lint! { /// // Good /// let a = std::ptr::null::(); /// ``` + #[clippy::version = "pre 1.29.0"] pub ZERO_PTR, style, "using `0 as *{const, mut} T`" @@ -259,6 +267,7 @@ declare_clippy_lint! { /// // let error_margin = std::f64::EPSILON; /// if (x - ONE).abs() < error_margin { } /// ``` + #[clippy::version = "pre 1.29.0"] pub FLOAT_CMP_CONST, restriction, "using `==` or `!=` on float constants instead of comparing difference with an epsilon" diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index 7c3f5f22ade..4b56eaebaea 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -46,6 +46,7 @@ declare_clippy_lint! { /// Foo { .. } => {}, /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub UNNEEDED_FIELD_PATTERN, restriction, "struct fields bound to a wildcard instead of using `..`" @@ -67,6 +68,7 @@ declare_clippy_lint! { /// // Good /// fn bar(a: i32, _b: i32) {} /// ``` + #[clippy::version = "pre 1.29.0"] pub DUPLICATE_UNDERSCORE_ARGUMENT, style, "function arguments having names which only differ by an underscore" @@ -85,6 +87,7 @@ declare_clippy_lint! { /// let mut x = 3; /// --x; /// ``` + #[clippy::version = "pre 1.29.0"] pub DOUBLE_NEG, style, "`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++" @@ -106,6 +109,7 @@ declare_clippy_lint! { /// // Good /// let y = 0x1A9BACD; /// ``` + #[clippy::version = "pre 1.29.0"] pub MIXED_CASE_HEX_LITERALS, style, "hex literals whose letter digits are not consistently upper- or lowercased" @@ -129,6 +133,7 @@ declare_clippy_lint! { /// // Good /// let y = 123832_i32; /// ``` + #[clippy::version = "pre 1.29.0"] pub UNSEPARATED_LITERAL_SUFFIX, restriction, "literals whose suffix is not separated by an underscore" @@ -189,6 +194,7 @@ declare_clippy_lint! { /// ``` /// /// prints `83` (as `83 == 0o123` while `123 == 0o173`). + #[clippy::version = "pre 1.29.0"] pub ZERO_PREFIXED_LITERAL, complexity, "integer literals starting with `0`" @@ -210,6 +216,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub BUILTIN_TYPE_SHADOW, style, "shadowing a builtin type" @@ -239,6 +246,7 @@ declare_clippy_lint! { /// y => (), /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub REDUNDANT_PATTERN, style, "using `name @ _` in a pattern" @@ -273,6 +281,7 @@ declare_clippy_lint! { /// _ => (), /// } /// ``` + #[clippy::version = "1.40.0"] pub UNNEEDED_WILDCARD_PATTERN, complexity, "tuple patterns with a wildcard pattern (`_`) is next to a rest pattern (`..`)" diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 5b2584d43a1..a8d41050856 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -63,6 +63,7 @@ declare_clippy_lint! { /// } /// # } /// ``` + #[clippy::version = "1.34.0"] pub MISSING_CONST_FOR_FN, nursery, "Lint functions definitions that could be made `const fn`" diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 6920b4f72ea..db6aab0671b 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// allowed-by-default lint for /// public members, but has no way to enforce documentation of private items. /// This lint fixes that. + #[clippy::version = "pre 1.29.0"] pub MISSING_DOCS_IN_PRIVATE_ITEMS, restriction, "detects missing documentation for public and private members" diff --git a/clippy_lints/src/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 448bfc2fdd6..68d49e0f150 100644 --- a/clippy_lints/src/missing_enforced_import_rename.rs +++ b/clippy_lints/src/missing_enforced_import_rename.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// ```rust,ignore /// use serde_json::Value as JsonValue; /// ``` + #[clippy::version = "1.55.0"] pub MISSING_ENFORCED_IMPORT_RENAMES, restriction, "enforce import renames" diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index b593c747498..ac2f16b49e3 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -52,6 +52,7 @@ declare_clippy_lint! { /// fn def_bar() {} // missing #[inline] /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub MISSING_INLINE_IN_PUBLIC_ITEMS, restriction, "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)" diff --git a/clippy_lints/src/module_style.rs b/clippy_lints/src/module_style.rs index d41b5474564..3b65f80cba2 100644 --- a/clippy_lints/src/module_style.rs +++ b/clippy_lints/src/module_style.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// stuff.rs /// lib.rs /// ``` + #[clippy::version = "1.57.0"] pub MOD_MODULE_FILES, restriction, "checks that module layout is consistent" @@ -61,6 +62,7 @@ declare_clippy_lint! { /// lib.rs /// ``` + #[clippy::version = "1.57.0"] pub SELF_NAMED_MODULE_FILES, restriction, "checks that module layout is consistent" diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index f45e68233a1..d182a7d5249 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -24,6 +24,7 @@ declare_clippy_lint! { /// ```rust /// let x = -17 % 3; /// ``` + #[clippy::version = "1.42.0"] pub MODULO_ARITHMETIC, restriction, "any modulo arithmetic statement" diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 816b2f275fb..e45cc86d417 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// ctrlc = "=3.1.0" /// ansi_term = "=0.11.0" /// ``` + #[clippy::version = "pre 1.29.0"] pub MULTIPLE_CRATE_VERSIONS, cargo, "multiple versions of the same crate being used" diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 8476257f086..5fe887a4573 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -72,6 +72,7 @@ declare_clippy_lint! { /// let _: HashSet = HashSet::new(); /// } /// ``` + #[clippy::version = "1.42.0"] pub MUTABLE_KEY_TYPE, suspicious, "Check for mutable `Map`/`Set` key type" diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 7c4cac29ba8..bcbea8f1e66 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -22,6 +22,7 @@ declare_clippy_lint! { /// # let mut y = 1; /// let x = &mut &mut y; /// ``` + #[clippy::version = "pre 1.29.0"] pub MUT_MUT, pedantic, "usage of double-mut refs, e.g., `&mut &mut ...`" diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs index b96fa4774cb..b1e6308d2e1 100644 --- a/clippy_lints/src/mut_mutex_lock.rs +++ b/clippy_lints/src/mut_mutex_lock.rs @@ -38,6 +38,7 @@ declare_clippy_lint! { /// let value = value_mutex.get_mut().unwrap(); /// *value += 1; /// ``` + #[clippy::version = "1.49.0"] pub MUT_MUTEX_LOCK, style, "`&mut Mutex::lock` does unnecessary locking" diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 8d5d7951fc5..63a1cf7b7d5 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -23,6 +23,7 @@ declare_clippy_lint! { /// // Good /// my_vec.push(&value) /// ``` + #[clippy::version = "pre 1.29.0"] pub UNNECESSARY_MUT_PASSED, style, "an argument passed as a mutable reference although the callee only demands an immutable reference" diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index ee50891cc31..fa7274990db 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// fn take_a_mut_parameter(_: &mut u32) -> bool { unimplemented!() } /// debug_assert!(take_a_mut_parameter(&mut 5)); /// ``` + #[clippy::version = "1.40.0"] pub DEBUG_ASSERT_WITH_MUT_CALL, nursery, "mutable arguments in `debug_assert{,_ne,_eq}!`" diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 5feddcbfc61..816377fe65e 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// # use std::sync::atomic::AtomicBool; /// let x = AtomicBool::new(y); /// ``` + #[clippy::version = "pre 1.29.0"] pub MUTEX_ATOMIC, perf, "using a mutex where an atomic value could be used instead" @@ -64,6 +65,7 @@ declare_clippy_lint! { /// # use std::sync::atomic::AtomicUsize; /// let x = AtomicUsize::new(0usize); /// ``` + #[clippy::version = "pre 1.29.0"] pub MUTEX_INTEGER, nursery, "using a mutex for an integer type" diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index c8a8750c2ff..9838d3cad9f 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -52,6 +52,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.47.0"] pub NEEDLESS_ARBITRARY_SELF_TYPE, complexity, "type of `self` parameter is already by default `Self`" diff --git a/clippy_lints/src/needless_bitwise_bool.rs b/clippy_lints/src/needless_bitwise_bool.rs index ad981599473..a8a8d174a82 100644 --- a/clippy_lints/src/needless_bitwise_bool.rs +++ b/clippy_lints/src/needless_bitwise_bool.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// let (x,y) = (true, false); /// if x && !y {} /// ``` + #[clippy::version = "1.54.0"] pub NEEDLESS_BITWISE_BOOL, pedantic, "Boolean expressions that use bitwise rather than lazy operators" diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 91944653500..3709f3948c2 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// ```rust,ignore /// !x /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_BOOL, complexity, "if-statements with plain booleans in the then- and else-clause, e.g., `if p { true } else { false }`" @@ -65,6 +66,7 @@ declare_clippy_lint! { /// if x {} /// if !y {} /// ``` + #[clippy::version = "pre 1.29.0"] pub BOOL_COMPARISON, complexity, "comparing a variable to a boolean, e.g., `if x == true` or `if x != true`" diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 085be6650cc..6709fed91bd 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -37,6 +37,7 @@ declare_clippy_lint! { /// let x: &i32 = &5; /// fun(x); /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_BORROW, style, "taking a reference that is going to be automatically dereferenced" @@ -63,6 +64,7 @@ declare_clippy_lint! { /// // use `&x` here /// } /// ``` + #[clippy::version = "1.54.0"] pub REF_BINDING_TO_REFERENCE, pedantic, "`ref` binding to a reference" diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 36879eda7c0..0fcc419e722 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -38,6 +38,7 @@ declare_clippy_lint! { /// let mut v = Vec::::new(); /// let _ = v.iter_mut().filter(|a| a.is_empty()); /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_BORROWED_REFERENCE, complexity, "destructuring a reference and borrowing the inner value" diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 7aa93ed7839..98a3bce1ff3 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -110,6 +110,7 @@ declare_clippy_lint! { /// # break; /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_CONTINUE, pedantic, "`continue` statements that can be replaced by a rearrangement of code" diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 9a6ddc72ce5..0c1da035173 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { /// println!("{}", elem); /// } /// ``` + #[clippy::version = "1.53.0"] pub NEEDLESS_FOR_EACH, pedantic, "using `for_each` where a `for` loop would be simpler" diff --git a/clippy_lints/src/needless_option_as_deref.rs b/clippy_lints/src/needless_option_as_deref.rs index e88e98e6081..a28b08c33ec 100644 --- a/clippy_lints/src/needless_option_as_deref.rs +++ b/clippy_lints/src/needless_option_as_deref.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// let a = Some(&1); /// let b = a; /// ``` + #[clippy::version = "1.57.0"] pub NEEDLESS_OPTION_AS_DEREF, complexity, "no-op use of `deref` or `deref_mut` method to `Option`." diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 352dc6f8bec..35877d51c0c 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -51,6 +51,7 @@ declare_clippy_lint! { /// assert_eq!(v.len(), 42); /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_PASS_BY_VALUE, pedantic, "functions taking arguments by value, but not consuming them in its body" diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 42e48336e15..3ca933ea8fb 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -53,6 +53,7 @@ declare_clippy_lint! { /// tr.and_then(|t| t.magic) /// } /// ``` + #[clippy::version = "1.51.0"] pub NEEDLESS_QUESTION_MARK, complexity, "Suggest `value.inner_option` instead of `Some(value.inner_option?)`. The same goes for `Result`." diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 2a33b7392ca..ed315efaa2f 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { /// ..zero_point /// }; /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_UPDATE, complexity, "using `Foo { ..base }` when there are no missing fields" diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 6ad49b70605..efe31a15441 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// _ => false, /// }; /// ``` + #[clippy::version = "pre 1.29.0"] pub NEG_CMP_OP_ON_PARTIAL_ORD, complexity, "The use of negated comparison operators on partially ordered types may produce confusing code." diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 1b15d29439f..cb67fab1740 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// ```ignore /// x * -1 /// ``` + #[clippy::version = "pre 1.29.0"] pub NEG_MULTIPLY, style, "multiplying integers with `-1`" diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 0ac27f1cba2..f0c0c89ca8f 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -45,6 +45,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEW_WITHOUT_DEFAULT, style, "`fn new() -> Self` method without `Default` implementation" diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 6dae8f32043..31134743d02 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -22,6 +22,7 @@ declare_clippy_lint! { /// ```rust /// 0; /// ``` + #[clippy::version = "pre 1.29.0"] pub NO_EFFECT, complexity, "statements with no effect" @@ -44,6 +45,7 @@ declare_clippy_lint! { /// ```rust,ignore /// let _i_serve_no_purpose = 1; /// ``` + #[clippy::version = "1.58.0"] pub NO_EFFECT_UNDERSCORE_BINDING, pedantic, "binding to `_` prefixed variable with no side-effect" @@ -62,6 +64,7 @@ declare_clippy_lint! { /// ```rust,ignore /// compute_array()[0]; /// ``` + #[clippy::version = "pre 1.29.0"] pub UNNECESSARY_OPERATION, complexity, "outer expressions with no effect" diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 2a85a67fa09..df82775d507 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -69,6 +69,7 @@ declare_clippy_lint! { /// STATIC_ATOM.store(9, SeqCst); /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance /// ``` + #[clippy::version = "pre 1.29.0"] pub DECLARE_INTERIOR_MUTABLE_CONST, style, "declaring `const` with interior mutability" @@ -113,6 +114,7 @@ declare_clippy_lint! { /// STATIC_ATOM.store(9, SeqCst); /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance /// ``` + #[clippy::version = "pre 1.29.0"] pub BORROW_INTERIOR_MUTABLE_CONST, style, "referencing `const` with interior mutability" diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 5b254bc8133..1a124e2d3cb 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -24,6 +24,7 @@ declare_clippy_lint! { /// let checked_exp = something; /// let checked_expr = something_else; /// ``` + #[clippy::version = "pre 1.29.0"] pub SIMILAR_NAMES, pedantic, "similarly named items and bindings" @@ -42,6 +43,7 @@ declare_clippy_lint! { /// ```ignore /// let (a, b, c, d, e, f, g) = (...); /// ``` + #[clippy::version = "pre 1.29.0"] pub MANY_SINGLE_CHAR_NAMES, pedantic, "too many single character bindings" @@ -62,6 +64,7 @@ declare_clippy_lint! { /// let ___1 = 1; /// let __1___2 = 11; /// ``` + #[clippy::version = "pre 1.29.0"] pub JUST_UNDERSCORES_AND_DIGITS, style, "unclear name" diff --git a/clippy_lints/src/non_octal_unix_permissions.rs b/clippy_lints/src/non_octal_unix_permissions.rs index 3b74f69d375..4b57dbc4c41 100644 --- a/clippy_lints/src/non_octal_unix_permissions.rs +++ b/clippy_lints/src/non_octal_unix_permissions.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// let mut options = OpenOptions::new(); /// options.mode(0o644); /// ``` + #[clippy::version = "1.53.0"] pub NON_OCTAL_UNIX_PERMISSIONS, correctness, "use of non-octal value to set unix file permissions, which will be translated into octal" diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 7ebf84d400f..9c07488bfe6 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -43,6 +43,7 @@ declare_clippy_lint! { /// ``` /// Use thread-safe types like [`std::sync::Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) /// or specify correct bounds on generic type parameters (`T: Send`). + #[clippy::version = "1.57.0"] pub NON_SEND_FIELDS_IN_SEND_TY, suspicious, "there is field that does not implement `Send` in a `Send` struct" diff --git a/clippy_lints/src/nonstandard_macro_braces.rs b/clippy_lints/src/nonstandard_macro_braces.rs index bab15217d52..3dcc9e26c9e 100644 --- a/clippy_lints/src/nonstandard_macro_braces.rs +++ b/clippy_lints/src/nonstandard_macro_braces.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// ```rust /// vec![1, 2, 3]; /// ``` + #[clippy::version = "1.55.0"] pub NONSTANDARD_MACRO_BRACES, nursery, "check consistent use of braces in macro" diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 5752342cf62..2c77100bdcf 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -22,6 +22,7 @@ declare_clippy_lint! { /// /// OpenOptions::new().read(true).truncate(true); /// ``` + #[clippy::version = "pre 1.29.0"] pub NONSENSICAL_OPEN_OPTIONS, correctness, "nonsensical combination of options for opening a file" diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index d7306628030..3f5286ba097 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// ```rust,no_run /// let _ = env!("HOME"); /// ``` + #[clippy::version = "1.43.0"] pub OPTION_ENV_UNWRAP, correctness, "using `option_env!(...).unwrap()` to get environment variable" diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index ed5583799fe..df72f4b0eb2 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -59,6 +59,7 @@ declare_clippy_lint! { /// y*y /// }, |foo| foo); /// ``` + #[clippy::version = "1.47.0"] pub OPTION_IF_LET_ELSE, nursery, "reimplementation of Option::map_or" diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 0f9e5ada3a8..6dabbd48031 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -19,6 +19,7 @@ declare_clippy_lint! { /// # let b = 2; /// a + b < a; /// ``` + #[clippy::version = "pre 1.29.0"] pub OVERFLOW_CHECK_CONDITIONAL, complexity, "overflow checks inspired by C which are likely to panic" diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 583c42b6563..8769c045214 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// Err(String::from("error")) /// } /// ``` + #[clippy::version = "1.48.0"] pub PANIC_IN_RESULT_FN, restriction, "functions of type `Result<..>` that contain `panic!()`, `todo!()`, `unreachable()`, `unimplemented()` or assertion" diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index d8d9081d6f1..edfac824ded 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -17,6 +17,7 @@ declare_clippy_lint! { /// ```no_run /// panic!("even with a good reason"); /// ``` + #[clippy::version = "1.40.0"] pub PANIC, restriction, "usage of the `panic!` macro" @@ -33,6 +34,7 @@ declare_clippy_lint! { /// ```no_run /// unimplemented!(); /// ``` + #[clippy::version = "pre 1.29.0"] pub UNIMPLEMENTED, restriction, "`unimplemented!` should not be present in production code" @@ -49,6 +51,7 @@ declare_clippy_lint! { /// ```no_run /// todo!(); /// ``` + #[clippy::version = "1.40.0"] pub TODO, restriction, "`todo!` should not be present in production code" @@ -65,6 +68,7 @@ declare_clippy_lint! { /// ```no_run /// unreachable!(); /// ``` + #[clippy::version = "1.40.0"] pub UNREACHABLE, restriction, "usage of the `unreachable!` macro" diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 4ec493e5f45..e827cdaae87 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -25,6 +25,7 @@ declare_clippy_lint! { /// fn ne(&self, other: &Foo) -> bool { !(self == other) } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub PARTIALEQ_NE_IMPL, complexity, "re-implementing `PartialEq::ne`" diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 6229b9608b3..3092ab8392a 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -65,6 +65,7 @@ declare_clippy_lint! { /// // Better /// fn foo(v: u32) {} /// ``` + #[clippy::version = "pre 1.29.0"] pub TRIVIALLY_COPY_PASS_BY_REF, pedantic, "functions taking small copyable arguments by reference" @@ -98,6 +99,7 @@ declare_clippy_lint! { /// // Good /// fn foo(v: &TooLarge) {} /// ``` + #[clippy::version = "1.49.0"] pub LARGE_TYPES_PASSED_BY_VALUE, pedantic, "functions taking large arguments by value" diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 3df7a72d295..8ebee9bd04d 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// x.push("bar"); /// assert_eq!(x, PathBuf::from("/foo/bar")); /// ``` + #[clippy::version = "1.36.0"] pub PATH_BUF_PUSH_OVERWRITE, nursery, "calling `push` with file system root on `PathBuf` can overwrite it" diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index e7bc2446590..3e7eef4edac 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -77,6 +77,7 @@ declare_clippy_lint! { /// *a += b; /// } /// ``` + #[clippy::version = "1.47.0"] pub PATTERN_TYPE_MISMATCH, restriction, "type of pattern does not match the expression type" diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index 1a8da00d9d6..cc0533c9f5d 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -42,6 +42,7 @@ declare_clippy_lint! { /// ### Example /// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7 /// * `-1i32.abs()` equals -1, while `(-1i32).abs()` equals 1 + #[clippy::version = "pre 1.29.0"] pub PRECEDENCE, complexity, "operations where precedence may be unclear" diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 8a36e20fc97..c08a19d520b 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -70,6 +70,7 @@ declare_clippy_lint! { /// // Good /// fn foo(&[u32]) { .. } /// ``` + #[clippy::version = "pre 1.29.0"] pub PTR_ARG, style, "fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively" @@ -96,6 +97,7 @@ declare_clippy_lint! { /// .. /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub CMP_NULL, style, "comparing a pointer to a null pointer, suggesting to use `.is_null()` instead" @@ -121,6 +123,7 @@ declare_clippy_lint! { /// ```ignore /// fn foo(&Foo) -> &mut Bar { .. } /// ``` + #[clippy::version = "pre 1.29.0"] pub MUT_FROM_REF, correctness, "fns that create mutable refs from immutable ref args" @@ -143,6 +146,7 @@ declare_clippy_lint! { /// // Good /// unsafe { std::slice::from_raw_parts(NonNull::dangling().as_ptr(), 0); } /// ``` + #[clippy::version = "1.53.0"] pub INVALID_NULL_PTR_USAGE, correctness, "invalid usage of a null pointer, suggesting `NonNull::dangling()` instead" diff --git a/clippy_lints/src/ptr_eq.rs b/clippy_lints/src/ptr_eq.rs index 2df34d6d9b9..3c126fc1ca6 100644 --- a/clippy_lints/src/ptr_eq.rs +++ b/clippy_lints/src/ptr_eq.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// /// assert!(std::ptr::eq(a, b)); /// ``` + #[clippy::version = "1.49.0"] pub PTR_EQ, style, "use `std::ptr::eq` when comparing raw pointers" diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index cfb5287c667..964564b5794 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -38,6 +38,7 @@ declare_clippy_lint! { /// ptr.add(offset); /// } /// ``` + #[clippy::version = "1.30.0"] pub PTR_OFFSET_WITH_CAST, complexity, "unneeded pointer offset cast" diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index f63ef163bcb..a5531993ee6 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// ```ignore /// option?; /// ``` + #[clippy::version = "pre 1.29.0"] pub QUESTION_MARK, style, "checks for expressions that could be replaced by the question mark operator" diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 87364a88ed0..09c64485bbb 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// # let x = vec![1]; /// x.iter().enumerate(); /// ``` + #[clippy::version = "pre 1.29.0"] pub RANGE_ZIP_WITH_LEN, complexity, "zipping iterator with a range when `enumerate()` would do" @@ -72,6 +73,7 @@ declare_clippy_lint! { /// ```rust,ignore /// for x..=y { .. } /// ``` + #[clippy::version = "pre 1.29.0"] pub RANGE_PLUS_ONE, pedantic, "`x..(y+1)` reads better as `x..=y`" @@ -100,6 +102,7 @@ declare_clippy_lint! { /// ```rust,ignore /// for x..y { .. } /// ``` + #[clippy::version = "pre 1.29.0"] pub RANGE_MINUS_ONE, pedantic, "`x..=(y-1)` reads better as `x..y`" @@ -132,6 +135,7 @@ declare_clippy_lint! { /// let sub = &arr[1..3]; /// } /// ``` + #[clippy::version = "1.45.0"] pub REVERSED_EMPTY_RANGES, correctness, "reversing the limits of range expressions, resulting in empty ranges" @@ -158,6 +162,7 @@ declare_clippy_lint! { ///# let x = 6; /// assert!((3..8).contains(&x)); /// ``` + #[clippy::version = "1.49.0"] pub MANUAL_RANGE_CONTAINS, style, "manually reimplementing {`Range`, `RangeInclusive`}`::contains`" diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index f7711b6fe94..1a2c86a7686 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -62,6 +62,7 @@ declare_clippy_lint! { /// /// Path::new("/a/b").join("c").to_path_buf(); /// ``` + #[clippy::version = "1.32.0"] pub REDUNDANT_CLONE, perf, "`clone()` of an owned value that is going to be dropped immediately" diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 90e3c3f4b3e..0de282542fc 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// // Good /// let a = 42 /// ``` + #[clippy::version = "pre 1.29.0"] pub REDUNDANT_CLOSURE_CALL, complexity, "throwaway closures called in the expression they are defined" diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 68b256d2944..93dbe936d58 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// print!("Moving on..."); /// } /// ``` + #[clippy::version = "1.50.0"] pub REDUNDANT_ELSE, pedantic, "`else` branch that can be removed without changing semantics" diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 47df4917510..0dea4a784b2 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// ```ignore /// let foo = Foo { bar }; /// ``` + #[clippy::version = "pre 1.29.0"] pub REDUNDANT_FIELD_NAMES, style, "checks for fields in struct literals where shorthands could be used" diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 919d4e11e5a..2cee3c14d7f 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// pub fn internal_fn() { } /// } /// ``` + #[clippy::version = "1.44.0"] pub REDUNDANT_PUB_CRATE, nursery, "Using `pub(crate)` visibility on items that are not crate visible due to the visibility of the module that contains them." diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 0c460150087..b2bd0103d11 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// x /// } /// ``` + #[clippy::version = "1.51.0"] pub REDUNDANT_SLICING, complexity, "redundant slicing of the whole range of a type" diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index d5a1a61da6b..ea5064217ab 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] /// static FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] /// ``` + #[clippy::version = "1.37.0"] pub REDUNDANT_STATIC_LIFETIMES, style, "Using explicit `'static` lifetime for constants or statics when elision rules would allow omitting them." diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index d543832e314..909d6971a54 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// ```rust,ignore /// let x: Option<&u32> = Some(&0u32); /// ``` + #[clippy::version = "1.49.0"] pub REF_OPTION_REF, pedantic, "use `Option<&T>` instead of `&Option<&T>`" diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index 70dff5ad313..22ae7a291d0 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// let a = f(b); /// let c = d; /// ``` + #[clippy::version = "pre 1.29.0"] pub DEREF_ADDROF, complexity, "use of `*&` or `*&mut` in an expression" @@ -124,6 +125,7 @@ declare_clippy_lint! { /// # let point = Point(30, 20); /// let x = point.0; /// ``` + #[clippy::version = "pre 1.29.0"] pub REF_IN_DEREF, complexity, "Use of reference in auto dereference expression." diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 5d08aee1e5f..8e5983b4773 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -22,6 +22,7 @@ declare_clippy_lint! { /// ```ignore /// Regex::new("|") /// ``` + #[clippy::version = "pre 1.29.0"] pub INVALID_REGEX, correctness, "invalid regular expressions" @@ -46,6 +47,7 @@ declare_clippy_lint! { /// ```ignore /// Regex::new("^foobar") /// ``` + #[clippy::version = "pre 1.29.0"] pub TRIVIAL_REGEX, nursery, "trivial regular expressions" diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs index e5e55ee7505..b5dd2de6337 100644 --- a/clippy_lints/src/repeat_once.rs +++ b/clippy_lints/src/repeat_once.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// let x = String::from("hello world").clone(); /// } /// ``` + #[clippy::version = "1.47.0"] pub REPEAT_ONCE, complexity, "using `.repeat(1)` instead of `String.clone()`, `str.to_string()` or `slice.to_vec()` " diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index e2b1a33746e..494bc7dda18 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -37,6 +37,7 @@ declare_clippy_lint! { /// String::new() /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub LET_AND_RETURN, style, "creating a let-binding and then immediately returning it like `let x = expr; x` at the end of a block" @@ -62,6 +63,7 @@ declare_clippy_lint! { /// x /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub NEEDLESS_RETURN, style, "using a return statement like `return expr;` where an expression would suffice" diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 737ff634e44..3f38d12fb55 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// fn foo(&self) {} /// } /// ``` + #[clippy::version = "1.57.0"] pub SAME_NAME_METHOD, restriction, "two method with same name" diff --git a/clippy_lints/src/self_assignment.rs b/clippy_lints/src/self_assignment.rs index fbd65fef7d1..b14f0518bdb 100644 --- a/clippy_lints/src/self_assignment.rs +++ b/clippy_lints/src/self_assignment.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// a.y = a.y; /// } /// ``` + #[clippy::version = "1.48.0"] pub SELF_ASSIGNMENT, correctness, "explicit self-assignment" diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 4ba5e1a0f53..dd73dbfe09e 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -32,6 +32,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.55.0"] pub SELF_NAMED_CONSTRUCTORS, style, "method should not have the same name as the type it is implemented for" diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index d3b4929a189..0b3bbbc8155 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// println!("Hello world"); /// } /// ``` + #[clippy::version = "1.52.0"] pub SEMICOLON_IF_NOTHING_RETURNED, pedantic, "add a semicolon if nothing is returned" diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 2cd0f85999c..a38b3c4ab69 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -15,6 +15,7 @@ declare_clippy_lint! { /// ### Example /// Implementing `Visitor::visit_string` but not /// `Visitor::visit_str`. + #[clippy::version = "pre 1.29.0"] pub SERDE_API_MISUSE, correctness, "various things that will negatively affect your serde experience" diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 64841f33cc3..5f82aed872c 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// // Good /// let y = &x; // use different variable name /// ``` + #[clippy::version = "pre 1.29.0"] pub SHADOW_SAME, restriction, "rebinding a name to itself, e.g., `let mut x = &mut x`" @@ -55,6 +56,7 @@ declare_clippy_lint! { /// let x = 2; /// let y = x + 1; /// ``` + #[clippy::version = "pre 1.29.0"] pub SHADOW_REUSE, restriction, "rebinding a name to an expression that re-uses the original value, e.g., `let x = x + 1`" @@ -84,6 +86,7 @@ declare_clippy_lint! { /// // Good /// let w = z; // use different variable name /// ``` + #[clippy::version = "pre 1.29.0"] pub SHADOW_UNRELATED, restriction, "rebinding a name without even using the original value" diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 87aa02b6585..28d32203da9 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); /// } /// ``` + #[clippy::version = "1.43.0"] pub SINGLE_COMPONENT_PATH_IMPORTS, style, "imports with single component path are redundant" diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index 3e4e4a8d0c0..df1e85afdd7 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// let mut y = [2u8; SIZE]; /// unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; /// ``` + #[clippy::version = "1.50.0"] pub SIZE_OF_IN_ELEMENT_COUNT, correctness, "using `size_of::` or `size_of_val::` where a count of elements of `T` is expected" diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 3608fe1472d..1ae772ef70b 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// let mut vec1 = vec![0; len]; /// let mut vec2 = vec![0; len]; /// ``` + #[clippy::version = "1.32.0"] pub SLOW_VECTOR_INITIALIZATION, perf, "slow vector initialization" diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 4ea1293d504..953d21e07a3 100644 --- a/clippy_lints/src/stable_sort_primitive.rs +++ b/clippy_lints/src/stable_sort_primitive.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// let mut vec = vec![2, 1, 3]; /// vec.sort_unstable(); /// ``` + #[clippy::version = "1.47.0"] pub STABLE_SORT_PRIMITIVE, perf, "use of sort() when sort_unstable() is equivalent" diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 6435107b8b4..368274440d5 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// x += ", World"; /// x.push_str(", World"); /// ``` + #[clippy::version = "pre 1.29.0"] pub STRING_ADD_ASSIGN, pedantic, "using `x = x + ..` where x is a `String` instead of `push_str()`" @@ -58,6 +59,7 @@ declare_clippy_lint! { /// let x = "Hello".to_owned(); /// x + ", World"; /// ``` + #[clippy::version = "pre 1.29.0"] pub STRING_ADD, restriction, "using `x + ..` where x is a `String` instead of `push_str()`" @@ -102,6 +104,7 @@ declare_clippy_lint! { /// // Good /// let bs = b"a byte string"; /// ``` + #[clippy::version = "pre 1.29.0"] pub STRING_LIT_AS_BYTES, nursery, "calling `as_bytes` on a string literal instead of using a byte string literal" @@ -125,6 +128,7 @@ declare_clippy_lint! { /// ```rust,should_panic /// &"Ölkanne"[1..]; /// ``` + #[clippy::version = "1.58.0"] pub STRING_SLICE, restriction, "slicing a string" @@ -227,6 +231,7 @@ declare_clippy_lint! { /// ```rust /// let _ = &"Hello World!"[6..11]; /// ``` + #[clippy::version = "1.50.0"] pub STRING_FROM_UTF8_AS_BYTES, complexity, "casting string slices to byte slices and back" @@ -371,6 +376,7 @@ declare_clippy_lint! { /// // example code which does not raise clippy warning /// let _ = "str".to_owned(); /// ``` + #[clippy::version = "pre 1.29.0"] pub STR_TO_STRING, restriction, "using `to_string()` on a `&str`, which should be `to_owned()`" @@ -420,6 +426,7 @@ declare_clippy_lint! { /// let msg = String::from("Hello World"); /// let _ = msg.clone(); /// ``` + #[clippy::version = "pre 1.29.0"] pub STRING_TO_STRING, restriction, "using `to_string()` on a `String`, which should be `clone()`" diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index 8bf40ec5312..be7431f11aa 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// let cstring = CString::new("foo").expect("CString::new failed"); /// let len = cstring.as_bytes().len(); /// ``` + #[clippy::version = "1.55.0"] pub STRLEN_ON_C_STRINGS, complexity, "using `libc::strlen` on a `CString` or `CStr` value, while `as_bytes().len()` or `to_bytes().len()` respectively can be used instead" diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 201aa067824..faf43fd9fc1 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -59,6 +59,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.50.0"] pub SUSPICIOUS_OPERATION_GROUPINGS, nursery, "groupings of binary operations that look suspiciously like typos" diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 682fad00a13..a3195de81d1 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -25,6 +25,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub SUSPICIOUS_ARITHMETIC_IMPL, suspicious, "suspicious use of operators in impl of arithmetic trait" @@ -46,6 +47,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub SUSPICIOUS_OP_ASSIGN_IMPL, suspicious, "suspicious use of operators in impl of OpAssign trait" diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index ef26de5b6b9..a8c7ca4c916 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// let mut b = 2; /// std::mem::swap(&mut a, &mut b); /// ``` + #[clippy::version = "pre 1.29.0"] pub MANUAL_SWAP, complexity, "manual swap of two variables" @@ -60,6 +61,7 @@ declare_clippy_lint! { /// # let mut b = 2; /// std::mem::swap(&mut a, &mut b); /// ``` + #[clippy::version = "pre 1.29.0"] pub ALMOST_SWAPPED, correctness, "`foo = bar; bar = foo` sequence" diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index 4a67cabf323..c9b4b245f4c 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -51,6 +51,7 @@ declare_clippy_lint! { /// second_string: String, ///} /// ``` + #[clippy::version = "1.41.0"] pub TABS_IN_DOC_COMMENTS, style, "using tabs in doc comments is not recommended" diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index a9da690339c..3766b8f8ed1 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -17,6 +17,7 @@ declare_clippy_lint! { /// ```rust /// (0, 0).0 = 1 /// ``` + #[clippy::version = "pre 1.29.0"] pub TEMPORARY_ASSIGNMENT, complexity, "assignments to temporaries" diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 1c14a919995..5eb58b47838 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// # let radix = 10; /// let is_digit = c.is_digit(radix); /// ``` + #[clippy::version = "1.41.0"] pub TO_DIGIT_IS_SOME, style, "`char.is_digit()` is clearer" diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index b7414cec87c..f8b6bdcd3e1 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.48.0"] pub TO_STRING_IN_DISPLAY, correctness, "`to_string` method used while implementing `Display` trait" diff --git a/clippy_lints/src/trailing_empty_array.rs b/clippy_lints/src/trailing_empty_array.rs index c216a1f81ea..47c0a84cd46 100644 --- a/clippy_lints/src/trailing_empty_array.rs +++ b/clippy_lints/src/trailing_empty_array.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// last: [u32; 0], /// } /// ``` + #[clippy::version = "1.58.0"] pub TRAILING_EMPTY_ARRAY, nursery, "struct with a trailing zero-sized array but without `#[repr(C)]` or another `repr` attribute" diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 73bdcae9e39..fb4abceac25 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// ```rust /// pub fn foo(t: T) where T: Copy + Clone {} /// ``` + #[clippy::version = "1.38.0"] pub TYPE_REPETITION_IN_BOUNDS, pedantic, "Types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`" @@ -57,6 +58,7 @@ declare_clippy_lint! { /// ```rust /// fn func(arg: T) where T: Clone + Default {} /// ``` + #[clippy::version = "1.47.0"] pub TRAIT_DUPLICATION_IN_BOUNDS, pedantic, "Check if the same trait bounds are specified twice during a function declaration" diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index e6acf1a94c9..3ad4ec74bf5 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// ```ignore /// let ptr: *const T = core::intrinsics::transmute('x') /// ``` + #[clippy::version = "pre 1.29.0"] pub WRONG_TRANSMUTE, correctness, "transmutes that are confusing at best, undefined behaviour at worst and always useless" @@ -55,6 +56,7 @@ declare_clippy_lint! { /// ```rust,ignore /// core::intrinsics::transmute(t); // where the result type is the same as `t`'s /// ``` + #[clippy::version = "pre 1.29.0"] pub USELESS_TRANSMUTE, nursery, "transmutes that have the same to and from types or could be a cast/coercion" @@ -80,6 +82,7 @@ declare_clippy_lint! { /// # let p: *const [i32] = &[]; /// p as *const [u16]; /// ``` + #[clippy::version = "1.47.0"] pub TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, complexity, "transmutes that could be a pointer cast" @@ -98,6 +101,7 @@ declare_clippy_lint! { /// core::intrinsics::transmute(t) // where the result type is the same as /// // `*t` or `&t`'s /// ``` + #[clippy::version = "pre 1.29.0"] pub CROSSPOINTER_TRANSMUTE, complexity, "transmutes that have to or from types that are a pointer to the other" @@ -125,6 +129,7 @@ declare_clippy_lint! { /// // can be written: /// let _: &T = &*p; /// ``` + #[clippy::version = "pre 1.29.0"] pub TRANSMUTE_PTR_TO_REF, complexity, "transmutes from a pointer to a reference type" @@ -158,6 +163,7 @@ declare_clippy_lint! { /// // should be: /// let _ = std::char::from_u32(x).unwrap(); /// ``` + #[clippy::version = "pre 1.29.0"] pub TRANSMUTE_INT_TO_CHAR, complexity, "transmutes from an integer to a `char`" @@ -191,6 +197,7 @@ declare_clippy_lint! { /// // should be: /// let _ = std::str::from_utf8(b).unwrap(); /// ``` + #[clippy::version = "pre 1.29.0"] pub TRANSMUTE_BYTES_TO_STR, complexity, "transmutes from a `&[u8]` to a `&str`" @@ -213,6 +220,7 @@ declare_clippy_lint! { /// // should be: /// let _: bool = x != 0; /// ``` + #[clippy::version = "pre 1.29.0"] pub TRANSMUTE_INT_TO_BOOL, complexity, "transmutes from an integer to a `bool`" @@ -235,6 +243,7 @@ declare_clippy_lint! { /// // should be: /// let _: f32 = f32::from_bits(1_u32); /// ``` + #[clippy::version = "pre 1.29.0"] pub TRANSMUTE_INT_TO_FLOAT, complexity, "transmutes from an integer to a float" @@ -257,6 +266,7 @@ declare_clippy_lint! { /// // should be: /// let _: u32 = 1f32.to_bits(); /// ``` + #[clippy::version = "1.41.0"] pub TRANSMUTE_FLOAT_TO_INT, complexity, "transmutes from a float to an integer" @@ -279,6 +289,7 @@ declare_clippy_lint! { /// // should be /// let x: [u8; 8] = 0i64.to_ne_bytes(); /// ``` + #[clippy::version = "1.58.0"] pub TRANSMUTE_NUM_TO_BYTES, complexity, "transmutes from a number to an array of `u8`" @@ -306,6 +317,7 @@ declare_clippy_lint! { /// let _ = ptr as *const f32; /// let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) }; /// ``` + #[clippy::version = "pre 1.29.0"] pub TRANSMUTE_PTR_TO_PTR, pedantic, "transmutes from a pointer to a pointer / a reference to a reference" @@ -337,6 +349,7 @@ declare_clippy_lint! { /// ```rust /// vec![2_u16].into_iter().map(u32::from).collect::>(); /// ``` + #[clippy::version = "1.40.0"] pub UNSOUND_COLLECTION_TRANSMUTE, correctness, "transmute between collections of layout-incompatible types" diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index ef80663d1da..7939dfedc3a 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -25,6 +25,7 @@ declare_clippy_lint! { /// ```rust /// let null_ref: &u64 = unsafe { std::mem::transmute(0 as *const u64) }; /// ``` + #[clippy::version = "1.35.0"] pub TRANSMUTING_NULL, correctness, "transmutes from a null pointer to a reference, which is undefined behavior" diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index cc450b1e599..e0e7ec9a452 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -41,6 +41,7 @@ declare_clippy_lint! { /// Ok(0) /// } /// ``` + #[clippy::version = "1.38.0"] pub TRY_ERR, style, "return errors explicitly rather than hiding them behind a `?`" diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index bbe07db5358..5a7ef760a30 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -43,6 +43,7 @@ declare_clippy_lint! { /// values: Vec, /// } /// ``` + #[clippy::version = "1.57.0"] pub BOX_COLLECTION, perf, "usage of `Box>`, vector elements are already on the heap" @@ -75,6 +76,7 @@ declare_clippy_lint! { /// values: Vec, /// } /// ``` + #[clippy::version = "1.33.0"] pub VEC_BOX, complexity, "usage of `Vec>` where T: Sized, vector elements are already on the heap" @@ -113,6 +115,7 @@ declare_clippy_lint! { /// Contents::None /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub OPTION_OPTION, pedantic, "usage of `Option>`" @@ -152,6 +155,7 @@ declare_clippy_lint! { /// # use std::collections::LinkedList; /// let x: LinkedList = LinkedList::new(); /// ``` + #[clippy::version = "pre 1.29.0"] pub LINKEDLIST, pedantic, "usage of LinkedList, usually a vector is faster, or a more specialized data structure like a `VecDeque`" @@ -176,6 +180,7 @@ declare_clippy_lint! { /// ```rust,ignore /// fn foo(bar: &T) { ... } /// ``` + #[clippy::version = "pre 1.29.0"] pub BORROWED_BOX, complexity, "a borrow of a boxed type" @@ -200,6 +205,7 @@ declare_clippy_lint! { /// ```rust /// fn foo(bar: &usize) {} /// ``` + #[clippy::version = "1.44.0"] pub REDUNDANT_ALLOCATION, perf, "redundant allocation" @@ -234,6 +240,7 @@ declare_clippy_lint! { /// ```rust,ignore /// fn foo(interned: Rc) { ... } /// ``` + #[clippy::version = "1.48.0"] pub RC_BUFFER, restriction, "shared ownership of a buffer type" @@ -255,6 +262,7 @@ declare_clippy_lint! { /// inner: Rc>>>, /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub TYPE_COMPLEXITY, complexity, "usage of very complex types that might be better factored into `type` definitions" @@ -287,6 +295,7 @@ declare_clippy_lint! { /// use std::cell::RefCell /// fn foo(interned: Rc>) { ... } /// ``` + #[clippy::version = "1.55.0"] pub RC_MUTEX, restriction, "usage of `Rc>`" diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index fbf66712261..c886faf5d28 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// // Safety: references are guaranteed to be non-null. /// let ptr = unsafe { NonNull::new_unchecked(a) }; /// ``` + #[clippy::version = "1.58.0"] pub UNDOCUMENTED_UNSAFE_BLOCKS, restriction, "creating an unsafe block without explaining why it is safe" diff --git a/clippy_lints/src/undropped_manually_drops.rs b/clippy_lints/src/undropped_manually_drops.rs index 09570616593..c58fa67a023 100644 --- a/clippy_lints/src/undropped_manually_drops.rs +++ b/clippy_lints/src/undropped_manually_drops.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S)); /// } /// ``` + #[clippy::version = "1.49.0"] pub UNDROPPED_MANUALLY_DROPS, correctness, "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index f49ce696a04..a514e8c44e2 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// ### Example /// You don't see it, but there may be a zero-width space or soft hyphen /// some­where in this text. + #[clippy::version = "1.49.0"] pub INVISIBLE_CHARACTERS, correctness, "using an invisible character in a string literal, which is confusing" @@ -44,6 +45,7 @@ declare_clippy_lint! { /// ```rust /// let x = String::from("\u{20ac}"); /// ``` + #[clippy::version = "pre 1.29.0"] pub NON_ASCII_LITERAL, restriction, "using any literal non-ASCII chars in a string literal instead of using the `\\u` escape" @@ -62,6 +64,7 @@ declare_clippy_lint! { /// ### Example /// You may not see it, but "à"" and "à"" aren't the same string. The /// former when escaped is actually `"a\u{300}"` while the latter is `"\u{e0}"`. + #[clippy::version = "pre 1.29.0"] pub UNICODE_NOT_NFC, pedantic, "using a Unicode literal not in NFC normal form (see [Unicode tr15](http://www.unicode.org/reports/tr15/) for further information)" diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index f3e8b688105..46cc76b150e 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -52,6 +52,7 @@ declare_clippy_lint! { /// // perform initialization with `remaining` /// vec.set_len(...); // Safe to call `set_len()` on initialized part /// ``` + #[clippy::version = "1.58.0"] pub UNINIT_VEC, correctness, "Vec with uninitialized data" diff --git a/clippy_lints/src/unit_hash.rs b/clippy_lints/src/unit_hash.rs index a3a3f2d41c7..26b4e0f58a8 100644 --- a/clippy_lints/src/unit_hash.rs +++ b/clippy_lints/src/unit_hash.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// WithValue(x) => x.hash(&mut state), /// } /// ``` + #[clippy::version = "1.58.0"] pub UNIT_HASH, correctness, "hashing a unit value, which does nothing" diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index db0f412f2a1..9fb8f236899 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -30,6 +30,7 @@ declare_clippy_lint! { /// let mut twins = vec!((1, 1), (2, 2)); /// twins.sort_by_key(|x| { x.1; }); /// ``` + #[clippy::version = "1.47.0"] pub UNIT_RETURN_EXPECTING_ORD, correctness, "fn arguments of type Fn(...) -> Ord returning the unit type ()." diff --git a/clippy_lints/src/unit_types/mod.rs b/clippy_lints/src/unit_types/mod.rs index 66b1abbe50b..d9f5b53b413 100644 --- a/clippy_lints/src/unit_types/mod.rs +++ b/clippy_lints/src/unit_types/mod.rs @@ -21,6 +21,7 @@ declare_clippy_lint! { /// 1; /// }; /// ``` + #[clippy::version = "pre 1.29.0"] pub LET_UNIT_VALUE, pedantic, "creating a `let` binding to a value of unit type, which usually can't be used afterwards" @@ -68,6 +69,7 @@ declare_clippy_lint! { /// assert_eq!({ foo(); }, { bar(); }); /// ``` /// will always succeed + #[clippy::version = "pre 1.29.0"] pub UNIT_CMP, correctness, "comparing unit values" @@ -88,6 +90,7 @@ declare_clippy_lint! { /// baz(a); /// }) /// ``` + #[clippy::version = "pre 1.29.0"] pub UNIT_ARG, complexity, "passing unit to a function" diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 1eafdee0352..0bcafde658a 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -24,6 +24,7 @@ declare_clippy_lint! { /// // ... /// } /// ``` + #[clippy::version = "1.44.0"] pub FN_ADDRESS_COMPARISONS, correctness, "comparison with an address of a function item" @@ -47,6 +48,7 @@ declare_clippy_lint! { /// ... /// } /// ``` + #[clippy::version = "1.44.0"] pub VTABLE_ADDRESS_COMPARISONS, correctness, "comparison with an address of a trait vtable" diff --git a/clippy_lints/src/unnecessary_self_imports.rs b/clippy_lints/src/unnecessary_self_imports.rs index 4cfd2df551f..839a4bdab09 100644 --- a/clippy_lints/src/unnecessary_self_imports.rs +++ b/clippy_lints/src/unnecessary_self_imports.rs @@ -26,6 +26,7 @@ declare_clippy_lint! { /// ```rust /// use std::io; /// ``` + #[clippy::version = "1.53.0"] pub UNNECESSARY_SELF_IMPORTS, restriction, "imports ending in `::{self}`, which can be omitted" diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 26b56e0f2f3..d024577f485 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// # let mut vec: Vec = Vec::new(); /// vec.sort_by_key(|a| a.foo()); /// ``` + #[clippy::version = "1.46.0"] pub UNNECESSARY_SORT_BY, complexity, "Use of `Vec::sort_by` when `Vec::sort_by_key` or `Vec::sort` would be clearer" diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index fcfa8403177..1728533f18b 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -49,6 +49,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "1.50.0"] pub UNNECESSARY_WRAPS, pedantic, "functions that only return `Ok` or `Some`" diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index d6cf7190abb..0bd151fed91 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// if let Some(0 | 2) = Some(0) {} /// } /// ``` + #[clippy::version = "1.46.0"] pub UNNESTED_OR_PATTERNS, pedantic, "unnested or-patterns, e.g., `Foo(Bar) | Foo(Baz) instead of `Foo(Bar | Baz)`" diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 3c694af2b9d..44b1989dbc6 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -21,6 +21,7 @@ declare_clippy_lint! { /// extern crate crossbeam; /// use crossbeam::{spawn_unsafe as spawn}; /// ``` + #[clippy::version = "pre 1.29.0"] pub UNSAFE_REMOVED_FROM_NAME, style, "`unsafe` removed from API names on import" diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index f4808682b69..1ccb78425c2 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// } /// let number_future = async { get_random_number_improved() }; /// ``` + #[clippy::version = "1.54.0"] pub UNUSED_ASYNC, pedantic, "finds async functions with no await statements" diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 031b182bd2f..d4b5c9770a2 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// Ok(()) /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub UNUSED_IO_AMOUNT, correctness, "unused written/read amount" diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index e7e249c79a2..fd9d5b52e50 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -29,6 +29,7 @@ declare_clippy_lint! { /// fn method() {} /// } /// ``` + #[clippy::version = "1.40.0"] pub UNUSED_SELF, pedantic, "methods that contain a `self` argument but don't use it" diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index 1164ac4938f..48c17fa2a40 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// ```rust /// fn return_unit() {} /// ``` + #[clippy::version = "1.31.0"] pub UNUSED_UNIT, style, "needless unit expression" diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index ebaa9dcbbf8..9e83cae79bc 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -39,6 +39,7 @@ declare_clippy_lint! { /// do_something_with(value) /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub UNNECESSARY_UNWRAP, complexity, "checks for calls of `unwrap[_err]()` that cannot fail" @@ -65,6 +66,7 @@ declare_clippy_lint! { /// ``` /// /// This code will always panic. The if condition should probably be inverted. + #[clippy::version = "pre 1.29.0"] pub PANICKING_UNWRAP, correctness, "checks for calls of `unwrap[_err]()` that will always fail" diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 6447e3fa2ca..994df85cb8a 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -51,6 +51,7 @@ declare_clippy_lint! { /// Ok(()) /// } /// ``` + #[clippy::version = "1.48.0"] pub UNWRAP_IN_RESULT, restriction, "functions of type `Result<..>` or `Option`<...> that contain `expect()` or `unwrap()`" diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index dbf335a70c8..4773e350760 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -33,6 +33,7 @@ declare_clippy_lint! { /// ```rust /// struct HttpResponse; /// ``` + #[clippy::version = "1.51.0"] pub UPPER_CASE_ACRONYMS, style, "capitalized acronyms are against the naming convention" diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 09aad296f03..059f7f647f8 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -51,6 +51,7 @@ declare_clippy_lint! { /// } /// } /// ``` + #[clippy::version = "pre 1.29.0"] pub USE_SELF, nursery, "unnecessary structure name repetition whereas `Self` is applicable" diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 88f11542072..0e4b32541c9 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -28,6 +28,7 @@ declare_clippy_lint! { /// // Good /// let s: String = format!("hello"); /// ``` + #[clippy::version = "1.45.0"] pub USELESS_CONVERSION, complexity, "calls to `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` which perform useless conversions to the same type" diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index d3234b5758a..79e7410c3a8 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// // Good /// foo(&[1, 2]); /// ``` + #[clippy::version = "pre 1.29.0"] pub USELESS_VEC, perf, "useless `vec!`" diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index b92b6ca4f43..1bc0eb6303c 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// ```rust /// let v = vec![0]; /// ``` + #[clippy::version = "1.51.0"] pub VEC_INIT_THEN_PUSH, perf, "`push` immediately after `Vec` creation" diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index 5c0429db6b8..3441d9ccdfa 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// ```rust /// vec!(1, 2, 3, 4, 5).resize(0, 5) /// ``` + #[clippy::version = "1.46.0"] pub VEC_RESIZE_TO_ZERO, correctness, "emptying a vector with `resize(0, an_int)` instead of `clear()` is probably an argument inversion mistake" diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index e07c12f4f16..ebdaff1e676 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -27,6 +27,7 @@ declare_clippy_lint! { /// # use std::fs; /// let mut bytes = fs::read("foo.txt").unwrap(); /// ``` + #[clippy::version = "1.44.0"] pub VERBOSE_FILE_READS, restriction, "use of `File::read_to_end` or `File::read_to_string`" diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index d0c98b6bd79..80d7b8a1b6d 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// [dependencies] /// regex = "*" /// ``` + #[clippy::version = "1.32.0"] pub WILDCARD_DEPENDENCIES, cargo, "wildcard dependencies being used" diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 2f3e525fdcf..832da66a536 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -34,6 +34,7 @@ declare_clippy_lint! { /// use std::cmp::Ordering; /// foo(Ordering::Less) /// ``` + #[clippy::version = "pre 1.29.0"] pub ENUM_GLOB_USE, pedantic, "use items that import all variants of an enum" @@ -86,6 +87,7 @@ declare_clippy_lint! { /// /// foo(); /// ``` + #[clippy::version = "1.43.0"] pub WILDCARD_IMPORTS, pedantic, "lint `use _::*` statements" diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 85d1f65c51f..1b3c15fdf23 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -31,6 +31,7 @@ declare_clippy_lint! { /// // Good /// println!(); /// ``` + #[clippy::version = "pre 1.29.0"] pub PRINTLN_EMPTY_STRING, style, "using `println!(\"\")` with an empty string" @@ -55,6 +56,7 @@ declare_clippy_lint! { /// # let name = "World"; /// println!("Hello {}!", name); /// ``` + #[clippy::version = "pre 1.29.0"] pub PRINT_WITH_NEWLINE, style, "using `print!()` with a format string that ends in a single newline" @@ -76,6 +78,7 @@ declare_clippy_lint! { /// ```rust /// println!("Hello world!"); /// ``` + #[clippy::version = "pre 1.29.0"] pub PRINT_STDOUT, restriction, "printing on stdout" @@ -97,6 +100,7 @@ declare_clippy_lint! { /// ```rust /// eprintln!("Hello world!"); /// ``` + #[clippy::version = "1.50.0"] pub PRINT_STDERR, restriction, "printing on stderr" @@ -116,6 +120,7 @@ declare_clippy_lint! { /// # let foo = "bar"; /// println!("{:?}", foo); /// ``` + #[clippy::version = "pre 1.29.0"] pub USE_DEBUG, restriction, "use of `Debug`-based formatting" @@ -142,6 +147,7 @@ declare_clippy_lint! { /// ```rust /// println!("foo"); /// ``` + #[clippy::version = "pre 1.29.0"] pub PRINT_LITERAL, style, "printing a literal with a format string" @@ -165,6 +171,7 @@ declare_clippy_lint! { /// // Good /// writeln!(buf); /// ``` + #[clippy::version = "pre 1.29.0"] pub WRITELN_EMPTY_STRING, style, "using `writeln!(buf, \"\")` with an empty string" @@ -191,6 +198,7 @@ declare_clippy_lint! { /// // Good /// writeln!(buf, "Hello {}!", name); /// ``` + #[clippy::version = "pre 1.29.0"] pub WRITE_WITH_NEWLINE, style, "using `write!()` with a format string that ends in a single newline" @@ -219,6 +227,7 @@ declare_clippy_lint! { /// // Good /// writeln!(buf, "foo"); /// ``` + #[clippy::version = "pre 1.29.0"] pub WRITE_LITERAL, style, "writing a literal with a format string" diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index e0746ce4d81..641681185a2 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -20,6 +20,7 @@ declare_clippy_lint! { /// // Good /// let nan = f32::NAN; /// ``` + #[clippy::version = "pre 1.29.0"] pub ZERO_DIVIDED_BY_ZERO, complexity, "usage of `0.0 / 0.0` to obtain NaN instead of `f32::NAN` or `f64::NAN`" diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index aa6b2614bbc..eb8436a501d 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -36,6 +36,7 @@ declare_clippy_lint! { /// todo!(); /// } /// ``` + #[clippy::version = "1.50.0"] pub ZERO_SIZED_MAP_VALUES, pedantic, "usage of map with zero-sized value type" -- cgit 1.4.1-3-g733a5 From 786f874c349b995ebed5e3d8f20db1cf65f20782 Mon Sep 17 00:00:00 2001 From: bors Date: Tue, 4 Jan 2022 22:32:02 +0000 Subject: New macro utils changelog: none Sorry, this is a big one. A lot of interrelated changes and I wanted to put the new utils to use to make sure they are somewhat battle-tested. We may want to divide some of the lint-specific refactoring commits into batches for smaller reviewing tasks. I could also split into more PRs. Introduces a bunch of new utils at `clippy_utils::macros::...`. Please read through the docs and give any feedback! I'm happy to introduce `MacroCall` and various functions to retrieve an instance. It feels like the missing puzzle piece. I'm also introducing `ExpnId` from rustc as "useful for Clippy too". `@rust-lang/clippy` Fixes #7843 by not parsing every node of macro implementations, at least the major offenders. I probably want to get rid of `is_expn_of` at some point. --- clippy_lints/src/assertions_on_constants.rs | 120 ++---- clippy_lints/src/attrs.rs | 18 +- clippy_lints/src/bool_assert_comparison.rs | 73 ++-- clippy_lints/src/doc.rs | 33 +- clippy_lints/src/eq_op.rs | 45 +-- clippy_lints/src/explicit_write.rs | 6 +- clippy_lints/src/fallible_impl_from.rs | 15 +- clippy_lints/src/format.rs | 33 +- clippy_lints/src/format_args.rs | 53 +-- clippy_lints/src/manual_assert.rs | 68 +--- clippy_lints/src/matches.rs | 24 +- clippy_lints/src/methods/expect_fun_call.rs | 21 +- clippy_lints/src/mutable_debug_assertion.rs | 42 +- clippy_lints/src/panic_in_result_fn.rs | 32 +- clippy_lints/src/panic_unimplemented.rs | 56 ++- clippy_lints/src/unit_types/unit_cmp.rs | 40 +- clippy_lints/src/utils/internal_lints.rs | 11 +- clippy_utils/Cargo.toml | 1 + clippy_utils/src/ast_utils.rs | 32 -- clippy_utils/src/higher.rs | 295 +------------- clippy_utils/src/lib.rs | 40 +- clippy_utils/src/macros.rs | 539 ++++++++++++++++++++++++++ clippy_utils/src/paths.rs | 5 - tests/ui/assertions_on_constants.rs | 1 - tests/ui/assertions_on_constants.stderr | 42 +- tests/ui/eq_op_macros.stderr | 44 +-- tests/ui/missing_panics_doc.stderr | 6 - tests/ui/panic_in_result_fn.stderr | 6 - tests/ui/panic_in_result_fn_assertions.stderr | 3 - tests/ui/panicking_macros.stderr | 21 - tests/ui/unit_cmp.stderr | 8 - 31 files changed, 868 insertions(+), 865 deletions(-) create mode 100644 clippy_utils/src/macros.rs (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index b7f414742f1..c82837746bd 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -1,12 +1,10 @@ use clippy_utils::consts::{constant, Constant}; use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::higher; -use clippy_utils::source::snippet_opt; -use clippy_utils::{is_direct_expn_of, is_expn_of, match_panic_call, peel_blocks}; -use if_chain::if_chain; -use rustc_hir::{Expr, ExprKind, UnOp}; +use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn}; +use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -36,107 +34,39 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]); impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - let lint_true = |is_debug: bool| { - span_lint_and_help( - cx, - ASSERTIONS_ON_CONSTANTS, - e.span, - if is_debug { - "`debug_assert!(true)` will be optimized out by the compiler" - } else { - "`assert!(true)` will be optimized out by the compiler" - }, - None, - "remove it", - ); + let Some(macro_call) = root_macro_call_first_node(cx, e) else { return }; + let is_debug = match cx.tcx.get_diagnostic_name(macro_call.def_id) { + Some(sym::debug_assert_macro) => true, + Some(sym::assert_macro) => false, + _ => return, }; - let lint_false_without_message = || { + let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else { return }; + let Some((Constant::Bool(val), _)) = constant(cx, cx.typeck_results(), condition) else { return }; + if val { span_lint_and_help( cx, ASSERTIONS_ON_CONSTANTS, - e.span, - "`assert!(false)` should probably be replaced", + macro_call.span, + &format!( + "`{}!(true)` will be optimized out by the compiler", + cx.tcx.item_name(macro_call.def_id) + ), None, - "use `panic!()` or `unreachable!()`", + "remove it", ); - }; - let lint_false_with_message = |panic_message: String| { + } else if !is_debug { + let (assert_arg, panic_arg) = match panic_expn { + PanicExpn::Empty => ("", ""), + _ => (", ..", ".."), + }; span_lint_and_help( cx, ASSERTIONS_ON_CONSTANTS, - e.span, - &format!("`assert!(false, {})` should probably be replaced", panic_message), + macro_call.span, + &format!("`assert!(false{})` should probably be replaced", assert_arg), None, - &format!("use `panic!({})` or `unreachable!({})`", panic_message, panic_message), + &format!("use `panic!({})` or `unreachable!({0})`", panic_arg), ); - }; - - if let Some(debug_assert_span) = is_expn_of(e.span, "debug_assert") { - if debug_assert_span.from_expansion() { - return; - } - if_chain! { - if let ExprKind::Unary(_, lit) = e.kind; - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), lit); - if is_true; - then { - lint_true(true); - } - }; - } else if let Some(assert_span) = is_direct_expn_of(e.span, "assert") { - if assert_span.from_expansion() { - return; - } - if let Some(assert_match) = match_assert_with_message(cx, e) { - match assert_match { - // matched assert but not message - AssertKind::WithoutMessage(false) => lint_false_without_message(), - AssertKind::WithoutMessage(true) | AssertKind::WithMessage(_, true) => lint_true(false), - AssertKind::WithMessage(panic_message, false) => lint_false_with_message(panic_message), - }; - } - } - } -} - -/// Result of calling `match_assert_with_message`. -enum AssertKind { - WithMessage(String, bool), - WithoutMessage(bool), -} - -/// Check if the expression matches -/// -/// ```rust,ignore -/// if !c { -/// { -/// ::std::rt::begin_panic(message, _) -/// } -/// } -/// ``` -/// -/// where `message` is any expression and `c` is a constant bool. -fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { - if_chain! { - if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr); - if let ExprKind::Unary(UnOp::Not, expr) = cond.kind; - // bind the first argument of the `assert!` macro - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr); - let begin_panic_call = peel_blocks(then); - // function call - if let Some(arg) = match_panic_call(cx, begin_panic_call); - // bind the second argument of the `assert!` macro if it exists - if let panic_message = snippet_opt(cx, arg.span); - // second argument of begin_panic is irrelevant - // as is the second match arm - then { - // an empty message occurs when it was generated by the macro - // (and not passed by the user) - return panic_message - .filter(|msg| !msg.is_empty()) - .map(|msg| AssertKind::WithMessage(msg, is_true)) - .or(Some(AssertKind::WithoutMessage(is_true))); } } - None } diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 0629674307b..a58d12ddd6b 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -1,9 +1,10 @@ //! checks for attributes use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::macros::{is_panic, macro_backtrace}; use clippy_utils::msrvs; use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments}; -use clippy_utils::{extract_msrv_attr, match_panic_def_id, meets_msrv}; +use clippy_utils::{extract_msrv_attr, meets_msrv}; use if_chain::if_chain; use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; use rustc_errors::Applicability; @@ -443,20 +444,15 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_ } fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool { + if macro_backtrace(expr.span).last().map_or(false, |macro_call| { + is_panic(cx, macro_call.def_id) || cx.tcx.item_name(macro_call.def_id) == sym::unreachable + }) { + return false; + } match &expr.kind { ExprKind::Block(block, _) => is_relevant_block(cx, typeck_results, block), ExprKind::Ret(Some(e)) => is_relevant_expr(cx, typeck_results, e), ExprKind::Ret(None) | ExprKind::Break(_, None) => false, - ExprKind::Call(path_expr, _) => { - if let ExprKind::Path(qpath) = &path_expr.kind { - typeck_results - .qpath_res(qpath, path_expr.hir_id) - .opt_def_id() - .map_or(true, |fun_id| !match_panic_def_id(cx, fun_id)) - } else { - true - } - }, _ => true, } } diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index d0b8c52a36a..ea2cfb0bc08 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -1,4 +1,5 @@ -use clippy_utils::{diagnostics::span_lint_and_sugg, higher, is_direct_expn_of, ty::implements_trait}; +use clippy_utils::macros::{find_assert_eq_args, root_macro_call_first_node}; +use clippy_utils::{diagnostics::span_lint_and_sugg, ty::implements_trait}; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, Lit}; @@ -66,44 +67,40 @@ fn is_impl_not_trait_with_bool_out(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let macros = ["assert_eq", "debug_assert_eq"]; - let inverted_macros = ["assert_ne", "debug_assert_ne"]; - - for mac in macros.iter().chain(inverted_macros.iter()) { - if let Some(span) = is_direct_expn_of(expr.span, mac) { - if let Some(args) = higher::extract_assert_macro_args(expr) { - if let [a, b, ..] = args[..] { - let nb_bool_args = usize::from(is_bool_lit(a)) + usize::from(is_bool_lit(b)); - - if nb_bool_args != 1 { - // If there are two boolean arguments, we definitely don't understand - // what's going on, so better leave things as is... - // - // Or there is simply no boolean and then we can leave things as is! - return; - } - - if !is_impl_not_trait_with_bool_out(cx, a) || !is_impl_not_trait_with_bool_out(cx, b) { - // At this point the expression which is not a boolean - // literal does not implement Not trait with a bool output, - // so we cannot suggest to rewrite our code - return; - } + let Some(macro_call) = root_macro_call_first_node(cx, expr) else { return }; + let macro_name = cx.tcx.item_name(macro_call.def_id); + if !matches!( + macro_name.as_str(), + "assert_eq" | "debug_assert_eq" | "assert_ne" | "debug_assert_ne" + ) { + return; + } + let Some ((a, b, _)) = find_assert_eq_args(cx, expr, macro_call.expn) else { return }; + if !(is_bool_lit(a) ^ is_bool_lit(b)) { + // If there are two boolean arguments, we definitely don't understand + // what's going on, so better leave things as is... + // + // Or there is simply no boolean and then we can leave things as is! + return; + } - let non_eq_mac = &mac[..mac.len() - 3]; - span_lint_and_sugg( - cx, - BOOL_ASSERT_COMPARISON, - span, - &format!("used `{}!` with a literal bool", mac), - "replace it with", - format!("{}!(..)", non_eq_mac), - Applicability::MaybeIncorrect, - ); - return; - } - } - } + if !is_impl_not_trait_with_bool_out(cx, a) || !is_impl_not_trait_with_bool_out(cx, b) { + // At this point the expression which is not a boolean + // literal does not implement Not trait with a bool output, + // so we cannot suggest to rewrite our code + return; } + + let macro_name = macro_name.as_str(); + let non_eq_mac = ¯o_name[..macro_name.len() - 3]; + span_lint_and_sugg( + cx, + BOOL_ASSERT_COMPARISON, + macro_call.span, + &format!("used `{}!` with a literal bool", macro_name), + "replace it with", + format!("{}!(..)", non_eq_mac), + Applicability::MaybeIncorrect, + ); } } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 3650e4f91a0..9d4195e400d 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -1,8 +1,9 @@ use clippy_utils::attrs::is_doc_hidden; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note, span_lint_and_then}; +use clippy_utils::macros::{is_panic, root_macro_call_first_node}; use clippy_utils::source::{first_line_of_span, snippet_with_applicability}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; -use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty}; +use clippy_utils::{is_entrypoint_fn, method_chain_args, return_ty}; use if_chain::if_chain; use itertools::Itertools; use rustc_ast::ast::{Async, AttrKind, Attribute, Fn, FnRetTy, ItemKind}; @@ -13,7 +14,7 @@ use rustc_errors::emitter::EmitterWriter; use rustc_errors::{Applicability, Handler, SuggestionStyle}; use rustc_hir as hir; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; -use rustc_hir::{AnonConst, Expr, ExprKind, QPath}; +use rustc_hir::{AnonConst, Expr}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; @@ -805,24 +806,17 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { return; } - // check for `begin_panic` - if_chain! { - if let ExprKind::Call(func_expr, _) = expr.kind; - if let ExprKind::Path(QPath::Resolved(_, path)) = func_expr.kind; - if let Some(path_def_id) = path.res.opt_def_id(); - if match_panic_def_id(self.cx, path_def_id); - if is_expn_of(expr.span, "unreachable").is_none(); - if !is_expn_of_debug_assertions(expr.span); - then { - self.panic_span = Some(expr.span); + if let Some(macro_call) = root_macro_call_first_node(self.cx, expr) { + if is_panic(self.cx, macro_call.def_id) + || matches!( + self.cx.tcx.item_name(macro_call.def_id).as_str(), + "assert" | "assert_eq" | "assert_ne" | "todo" + ) + { + self.panic_span = Some(macro_call.span); } } - // check for `assert_eq` or `assert_ne` - if is_expn_of(expr.span, "assert_eq").is_some() || is_expn_of(expr.span, "assert_ne").is_some() { - self.panic_span = Some(expr.span); - } - // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); @@ -844,8 +838,3 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) } } - -fn is_expn_of_debug_assertions(span: Span) -> bool { - const MACRO_NAMES: &[&str] = &["debug_assert", "debug_assert_eq", "debug_assert_ne"]; - MACRO_NAMES.iter().any(|name| is_expn_of(span, name).is_some()) -} diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 10123460527..df75b815436 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -1,10 +1,11 @@ use clippy_utils::diagnostics::{multispan_sugg, span_lint, span_lint_and_then}; +use clippy_utils::macros::{find_assert_eq_args, first_node_macro_backtrace}; use clippy_utils::source::snippet; use clippy_utils::ty::{implements_trait, is_copy}; -use clippy_utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, is_expn_of, is_in_test_function}; +use clippy_utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, is_in_test_function}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, StmtKind}; +use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -68,32 +69,26 @@ declare_clippy_lint! { declare_lint_pass!(EqOp => [EQ_OP, OP_REF]); -const ASSERT_MACRO_NAMES: [&str; 4] = ["assert_eq", "assert_ne", "debug_assert_eq", "debug_assert_ne"]; - impl<'tcx> LateLintPass<'tcx> for EqOp { #[allow(clippy::similar_names, clippy::too_many_lines)] fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Block(block, _) = e.kind { - for stmt in block.stmts { - for amn in &ASSERT_MACRO_NAMES { - if_chain! { - if is_expn_of(stmt.span, amn).is_some(); - if let StmtKind::Semi(matchexpr) = stmt.kind; - if let Some(macro_args) = higher::extract_assert_macro_args(matchexpr); - if macro_args.len() == 2; - let (lhs, rhs) = (macro_args[0], macro_args[1]); - if eq_expr_value(cx, lhs, rhs); - if !is_in_test_function(cx.tcx, e.hir_id); - then { - span_lint( - cx, - EQ_OP, - lhs.span.to(rhs.span), - &format!("identical args used in this `{}!` macro call", amn), - ); - } - } - } + if_chain! { + if let Some((macro_call, macro_name)) = first_node_macro_backtrace(cx, e).find_map(|macro_call| { + let name = cx.tcx.item_name(macro_call.def_id); + matches!(name.as_str(), "assert_eq" | "assert_ne" | "debug_assert_eq" | "debug_assert_ne") + .then(|| (macro_call, name)) + }); + if let Some((lhs, rhs, _)) = find_assert_eq_args(cx, e, macro_call.expn); + if eq_expr_value(cx, lhs, rhs); + if macro_call.is_local(); + if !is_in_test_function(cx.tcx, e.hir_id); + then { + span_lint( + cx, + EQ_OP, + lhs.span.to(rhs.span), + &format!("identical args used in this `{}!` macro call", macro_name), + ); } } if let ExprKind::Binary(op, left, right) = e.kind { diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 6b327b9ce17..98e5234e0aa 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; -use clippy_utils::higher::FormatArgsExpn; +use clippy_utils::macros::FormatArgsExpn; use clippy_utils::{is_expn_of, match_function_call, paths}; use if_chain::if_chain; use rustc_errors::Applicability; @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { } else { None }; - if let Some(format_args) = FormatArgsExpn::parse(write_arg); + if let Some(format_args) = FormatArgsExpn::parse(cx, write_arg); then { let calling_macro = // ordering is important here, since `writeln!` uses `write!` internally @@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { ) }; let msg = format!("use of `{}.unwrap()`", used); - if let [write_output] = *format_args.format_string_symbols { + if let [write_output] = *format_args.format_string_parts { let mut write_output = write_output.to_string(); if write_output.ends_with('\n') { write_output.pop(); diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 05d300058cf..02f1baf27fa 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -1,6 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::macros::{is_panic, root_macro_call_first_node}; +use clippy_utils::method_chain_args; use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::{is_expn_of, match_panic_def_id, method_chain_args}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; @@ -68,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef]) { use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; - use rustc_hir::{Expr, ExprKind, ImplItemKind, QPath}; + use rustc_hir::{Expr, ImplItemKind}; struct FindPanicUnwrap<'a, 'tcx> { lcx: &'a LateContext<'tcx>, @@ -80,14 +81,8 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - // check for `begin_panic` - if_chain! { - if let ExprKind::Call(func_expr, _) = expr.kind; - if let ExprKind::Path(QPath::Resolved(_, path)) = func_expr.kind; - if let Some(path_def_id) = path.res.opt_def_id(); - if match_panic_def_id(self.lcx, path_def_id); - if is_expn_of(expr.span, "unreachable").is_none(); - then { + if let Some(macro_call) = root_macro_call_first_node(self.lcx, expr) { + if is_panic(self.lcx, macro_call.def_id) { self.result.push(expr.span); } } diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 3f043e5f2f1..688d8f8630f 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::higher::FormatExpn; +use clippy_utils::macros::{root_macro_call_first_node, FormatArgsExpn}; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; use clippy_utils::sugg::Sugg; use if_chain::if_chain; @@ -43,38 +43,41 @@ declare_lint_pass!(UselessFormat => [USELESS_FORMAT]); impl<'tcx> LateLintPass<'tcx> for UselessFormat { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let FormatExpn { call_site, format_args } = match FormatExpn::parse(expr) { - Some(e) if !e.call_site.from_expansion() => e, - _ => return, + let (format_args, call_site) = if_chain! { + if let Some(macro_call) = root_macro_call_first_node(cx, expr); + if cx.tcx.is_diagnostic_item(sym::format_macro, macro_call.def_id); + if let Some(format_args) = FormatArgsExpn::find_nested(cx, expr, macro_call.expn); + then { + (format_args, macro_call.span) + } else { + return + } }; let mut applicability = Applicability::MachineApplicable; if format_args.value_args.is_empty() { - if format_args.format_string_parts.is_empty() { - span_useless_format_empty(cx, call_site, "String::new()".to_owned(), applicability); - } else { - if_chain! { - if let [e] = &*format_args.format_string_parts; - if let ExprKind::Lit(lit) = &e.kind; - if let Some(s_src) = snippet_opt(cx, lit.span); - then { + match *format_args.format_string_parts { + [] => span_useless_format_empty(cx, call_site, "String::new()".to_owned(), applicability), + [_] => { + if let Some(s_src) = snippet_opt(cx, format_args.format_string_span) { // Simulate macro expansion, converting {{ and }} to { and }. let s_expand = s_src.replace("{{", "{").replace("}}", "}"); let sugg = format!("{}.to_string()", s_expand); span_useless_format(cx, call_site, sugg, applicability); } - } + }, + [..] => {}, } } else if let [value] = *format_args.value_args { if_chain! { - if format_args.format_string_symbols == [kw::Empty]; + if format_args.format_string_parts == [kw::Empty]; if match cx.typeck_results().expr_ty(value).peel_refs().kind() { ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did), ty::Str => true, _ => false, }; if let Some(args) = format_args.args(); - if args.iter().all(|arg| arg.is_display() && !arg.has_string_formatting()); + if args.iter().all(|arg| arg.format_trait == sym::Display && !arg.has_string_formatting()); then { let is_new_string = match value.kind { ExprKind::Binary(..) => true, diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index f0e1a67dcdd..ae423d799d7 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::higher::{FormatArgsArg, FormatArgsExpn, FormatExpn}; +use clippy_utils::macros::{FormatArgsArg, FormatArgsExpn}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::implements_trait; use clippy_utils::{is_diag_trait_item, match_def_path, paths}; @@ -83,7 +83,7 @@ const FORMAT_MACRO_DIAG_ITEMS: &[Symbol] = &[sym::format_macro, sym::std_panic_m impl<'tcx> LateLintPass<'tcx> for FormatArgs { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if_chain! { - if let Some(format_args) = FormatArgsExpn::parse(expr); + if let Some(format_args) = FormatArgsExpn::parse(cx, expr); let expr_expn_data = expr.span.ctxt().outer_expn_data(); let outermost_expn_data = outermost_expn_data(expr_expn_data); if let Some(macro_def_id) = outermost_expn_data.macro_def_id; @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs { if let Some(args) = format_args.args(); then { for (i, arg) in args.iter().enumerate() { - if !arg.is_display() { + if arg.format_trait != sym::Display { continue; } if arg.has_string_formatting() { @@ -106,8 +106,8 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs { if is_aliased(&args, i) { continue; } - check_format_in_format_args(cx, outermost_expn_data.call_site, name, arg); - check_to_string_in_format_args(cx, name, arg); + check_format_in_format_args(cx, outermost_expn_data.call_site, name, arg.value); + check_to_string_in_format_args(cx, name, arg.value); } } } @@ -122,30 +122,31 @@ fn outermost_expn_data(expn_data: ExpnData) -> ExpnData { } } -fn check_format_in_format_args(cx: &LateContext<'_>, call_site: Span, name: Symbol, arg: &FormatArgsArg<'_>) { - if_chain! { - if FormatExpn::parse(arg.value).is_some(); - if !arg.value.span.ctxt().outer_expn_data().call_site.from_expansion(); - then { - span_lint_and_then( - cx, - FORMAT_IN_FORMAT_ARGS, - call_site, - &format!("`format!` in `{}!` args", name), - |diag| { - diag.help(&format!( - "combine the `format!(..)` arguments with the outer `{}!(..)` call", - name - )); - diag.help("or consider changing `format!` to `format_args!`"); - }, - ); - } +fn check_format_in_format_args(cx: &LateContext<'_>, call_site: Span, name: Symbol, arg: &Expr<'_>) { + let expn_data = arg.span.ctxt().outer_expn_data(); + if expn_data.call_site.from_expansion() { + return; + } + let Some(mac_id) = expn_data.macro_def_id else { return }; + if !cx.tcx.is_diagnostic_item(sym::format_macro, mac_id) { + return; } + span_lint_and_then( + cx, + FORMAT_IN_FORMAT_ARGS, + call_site, + &format!("`format!` in `{}!` args", name), + |diag| { + diag.help(&format!( + "combine the `format!(..)` arguments with the outer `{}!(..)` call", + name + )); + diag.help("or consider changing `format!` to `format_args!`"); + }, + ); } -fn check_to_string_in_format_args<'tcx>(cx: &LateContext<'tcx>, name: Symbol, arg: &FormatArgsArg<'tcx>) { - let value = arg.value; +fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Expr<'_>) { if_chain! { if !value.span.from_expansion(); if let ExprKind::MethodCall(_, _, [receiver], _) = value.kind; diff --git a/clippy_lints/src/manual_assert.rs b/clippy_lints/src/manual_assert.rs index 5a2a965716c..e3a34b22e32 100644 --- a/clippy_lints/src/manual_assert.rs +++ b/clippy_lints/src/manual_assert.rs @@ -1,11 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::higher::PanicExpn; +use clippy_utils::macros::{root_macro_call, FormatArgsExpn}; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::{is_expn_of, sugg}; +use clippy_utils::{peel_blocks_with_stmt, sugg}; use rustc_errors::Applicability; -use rustc_hir::{Block, Expr, ExprKind, StmtKind, UnOp}; +use rustc_hir::{Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -35,64 +36,33 @@ declare_clippy_lint! { declare_lint_pass!(ManualAssert => [MANUAL_ASSERT]); impl LateLintPass<'_> for ManualAssert { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { if_chain! { - if let Expr { - kind: ExprKind:: If(cond, Expr { - kind: ExprKind::Block( - Block { - stmts: [stmt], - .. - }, - _), - .. - }, None), - .. - } = &expr; - if is_expn_of(stmt.span, "panic").is_some(); + if let ExprKind::If(cond, then, None) = expr.kind; if !matches!(cond.kind, ExprKind::Let(_)); - if let StmtKind::Semi(semi) = stmt.kind; + if !expr.span.from_expansion(); + let then = peel_blocks_with_stmt(then); + if let Some(macro_call) = root_macro_call(then.span); + if cx.tcx.item_name(macro_call.def_id) == sym::panic; if !cx.tcx.sess.source_map().is_multiline(cond.span); - + if let Some(format_args) = FormatArgsExpn::find_nested(cx, then, macro_call.expn); then { - let call = if_chain! { - if let ExprKind::Block(block, _) = semi.kind; - if let Some(init) = block.expr; - then { - init - } else { - semi - } - }; - let span = if let Some(panic_expn) = PanicExpn::parse(call) { - match *panic_expn.format_args.value_args { - [] => panic_expn.format_args.format_string_span, - [.., last] => panic_expn.format_args.format_string_span.to(last.span), - } - } else if let ExprKind::Call(_, [format_args]) = call.kind { - format_args.span - } else { - return - }; let mut applicability = Applicability::MachineApplicable; - let sugg = snippet_with_applicability(cx, span, "..", &mut applicability); - let cond_sugg = if let ExprKind::DropTemps(e, ..) = cond.kind { - if let Expr{kind: ExprKind::Unary(UnOp::Not, not_expr), ..} = e { - sugg::Sugg::hir_with_applicability(cx, not_expr, "..", &mut applicability).maybe_par().to_string() - } else { - format!("!{}", sugg::Sugg::hir_with_applicability(cx, e, "..", &mut applicability).maybe_par()) - } - } else { - format!("!{}", sugg::Sugg::hir_with_applicability(cx, cond, "..", &mut applicability).maybe_par()) + let format_args_snip = snippet_with_applicability(cx, format_args.inputs_span(), "..", &mut applicability); + let cond = cond.peel_drop_temps(); + let (cond, not) = match cond.kind { + ExprKind::Unary(UnOp::Not, e) => (e, ""), + _ => (cond, "!"), }; - + let cond_sugg = sugg::Sugg::hir_with_applicability(cx, cond, "..", &mut applicability).maybe_par(); + let sugg = format!("assert!({not}{cond_sugg}, {format_args_snip});"); span_lint_and_sugg( cx, MANUAL_ASSERT, expr.span, "only a `panic!` in `if`-then statement", "try", - format!("assert!({}, {});", cond_sugg, sugg), + sugg, Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 22970507f96..0d693499bc6 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -2,16 +2,17 @@ use clippy_utils::consts::{constant, constant_full_int, miri_to_const, FullInt}; use clippy_utils::diagnostics::{ multispan_sugg, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, }; -use clippy_utils::higher; +use clippy_utils::macros::{is_panic, root_macro_call}; use clippy_utils::source::{expr_block, indent_of, snippet, snippet_block, snippet_opt, snippet_with_applicability}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs}; use clippy_utils::visitors::is_local_used; use clippy_utils::{ - get_parent_expr, is_expn_of, is_lang_ctor, is_lint_allowed, is_refutable, is_unit_expr, is_wild, meets_msrv, msrvs, + get_parent_expr, is_lang_ctor, is_lint_allowed, is_refutable, is_unit_expr, is_wild, meets_msrv, msrvs, path_to_local, path_to_local_id, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, strip_pat_refs, }; +use clippy_utils::{higher, peel_blocks_with_stmt}; use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash}; use core::iter::{once, ExactSizeIterator}; use if_chain::if_chain; @@ -974,7 +975,8 @@ fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm } if_chain! { if matching_wild; - if is_panic_call(arm.body); + if let Some(macro_call) = root_macro_call(peel_blocks_with_stmt(arm.body).span); + if is_panic(cx, macro_call.def_id); then { // `Err(_)` or `Err(_e)` arm with `panic!` found span_lint_and_note(cx, @@ -1179,22 +1181,6 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) }; } -// If the block contains only a `panic!` macro (as expression or statement) -fn is_panic_call(expr: &Expr<'_>) -> bool { - // Unwrap any wrapping blocks - let span = if let ExprKind::Block(block, _) = expr.kind { - match (&block.expr, block.stmts.len(), block.stmts.first()) { - (&Some(exp), 0, _) => exp.span, - (&None, 1, Some(stmt)) => stmt.span, - _ => return false, - } - } else { - expr.span - }; - - is_expn_of(span, "panic").is_some() && is_expn_of(span, "unreachable").is_none() -} - fn check_match_ref_pats<'a, 'b, I>(cx: &LateContext<'_>, ex: &Expr<'_>, pats: I, expr: &Expr<'_>) where 'b: 'a, diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 0ec9387f9c4..866eaff5b1d 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::higher::FormatExpn; +use clippy_utils::macros::{root_macro_call_first_node, FormatArgsExpn}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; @@ -14,7 +14,13 @@ use super::EXPECT_FUN_CALL; /// Checks for the `EXPECT_FUN_CALL` lint. #[allow(clippy::too_many_lines)] -pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Span, name: &str, args: &[hir::Expr<'_>]) { +pub(super) fn check( + cx: &LateContext<'tcx>, + expr: &hir::Expr<'_>, + method_span: Span, + name: &str, + args: &'tcx [hir::Expr<'tcx>], +) { // Strip `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or // `&str` fn get_arg_root<'a>(cx: &LateContext<'_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { @@ -128,11 +134,12 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa let mut applicability = Applicability::MachineApplicable; //Special handling for `format!` as arg_root - if let Some(format_expn) = FormatExpn::parse(arg_root) { - let span = match *format_expn.format_args.value_args { - [] => format_expn.format_args.format_string_span, - [.., last] => format_expn.format_args.format_string_span.to(last.span), - }; + if let Some(macro_call) = root_macro_call_first_node(cx, arg_root) { + if !cx.tcx.is_diagnostic_item(sym::format_macro, macro_call.def_id) { + return; + } + let Some(format_args) = FormatArgsExpn::find_nested(cx, arg_root, macro_call.expn) else { return }; + let span = format_args.inputs_span(); let sugg = snippet_with_applicability(cx, span, "..", &mut applicability); span_lint_and_sugg( cx, diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index fa7274990db..49d4b3a1850 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::{higher, is_direct_expn_of}; +use clippy_utils::macros::{find_assert_eq_args, root_macro_call_first_node}; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability}; use rustc_lint::{LateContext, LateLintPass}; @@ -34,26 +34,30 @@ declare_clippy_lint! { declare_lint_pass!(DebugAssertWithMutCall => [DEBUG_ASSERT_WITH_MUT_CALL]); -const DEBUG_MACRO_NAMES: [&str; 3] = ["debug_assert", "debug_assert_eq", "debug_assert_ne"]; - impl<'tcx> LateLintPass<'tcx> for DebugAssertWithMutCall { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - for dmn in &DEBUG_MACRO_NAMES { - if is_direct_expn_of(e.span, dmn).is_some() { - if let Some(macro_args) = higher::extract_assert_macro_args(e) { - for arg in macro_args { - let mut visitor = MutArgVisitor::new(cx); - visitor.visit_expr(arg); - if let Some(span) = visitor.expr_span() { - span_lint( - cx, - DEBUG_ASSERT_WITH_MUT_CALL, - span, - &format!("do not call a function with mutable arguments inside of `{}!`", dmn), - ); - } - } - } + let Some(macro_call) = root_macro_call_first_node(cx, e) else { return }; + let macro_name = cx.tcx.item_name(macro_call.def_id); + if !matches!( + macro_name.as_str(), + "debug_assert" | "debug_assert_eq" | "debug_assert_ne" + ) { + return; + } + let Some((lhs, rhs, _)) = find_assert_eq_args(cx, e, macro_call.expn) else { return }; + for arg in [lhs, rhs] { + let mut visitor = MutArgVisitor::new(cx); + visitor.visit_expr(arg); + if let Some(span) = visitor.expr_span() { + span_lint( + cx, + DEBUG_ASSERT_WITH_MUT_CALL, + span, + &format!( + "do not call a function with mutable arguments inside of `{}!`", + macro_name + ), + ); } } } diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 8769c045214..b7a56970b33 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -1,8 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::macros::root_macro_call_first_node; +use clippy_utils::return_ty; use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::{find_macro_calls, is_expn_of, return_ty}; +use clippy_utils::visitors::expr_visitor_no_bodies; use rustc_hir as hir; -use rustc_hir::intravisit::FnKind; +use rustc_hir::intravisit::{FnKind, Visitor}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; @@ -55,19 +57,19 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn { } fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir::Body<'tcx>) { - let mut panics = find_macro_calls( - &[ - "unimplemented", - "unreachable", - "panic", - "todo", - "assert", - "assert_eq", - "assert_ne", - ], - body, - ); - panics.retain(|span| is_expn_of(*span, "debug_assert").is_none()); + let mut panics = Vec::new(); + expr_visitor_no_bodies(|expr| { + let Some(macro_call) = root_macro_call_first_node(cx, expr) else { return true }; + if matches!( + &*cx.tcx.item_name(macro_call.def_id).as_str(), + "unimplemented" | "unreachable" | "panic" | "todo" | "assert" | "assert_eq" | "assert_ne" + ) { + panics.push(macro_call.span); + return false; + } + true + }) + .visit_expr(&body.value); if !panics.is_empty() { span_lint_and_then( cx, diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index edfac824ded..6ef6b9a20aa 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -1,10 +1,8 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::{is_expn_of, match_panic_call}; -use if_chain::if_chain; +use clippy_utils::macros::{is_panic, root_macro_call_first_node}; use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::Span; declare_clippy_lint! { /// ### What it does @@ -78,37 +76,37 @@ declare_lint_pass!(PanicUnimplemented => [UNIMPLEMENTED, UNREACHABLE, TODO, PANI impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if match_panic_call(cx, expr).is_some() - && (is_expn_of(expr.span, "debug_assert").is_none() && is_expn_of(expr.span, "assert").is_none()) - { - let span = get_outer_span(expr); - if is_expn_of(expr.span, "unimplemented").is_some() { + let Some(macro_call) = root_macro_call_first_node(cx, expr) else { return }; + if is_panic(cx, macro_call.def_id) { + span_lint( + cx, + PANIC, + macro_call.span, + "`panic` should not be present in production code", + ); + return; + } + match cx.tcx.item_name(macro_call.def_id).as_str() { + "todo" => { + span_lint( + cx, + TODO, + macro_call.span, + "`todo` should not be present in production code", + ); + }, + "unimplemented" => { span_lint( cx, UNIMPLEMENTED, - span, + macro_call.span, "`unimplemented` should not be present in production code", ); - } else if is_expn_of(expr.span, "todo").is_some() { - span_lint(cx, TODO, span, "`todo` should not be present in production code"); - } else if is_expn_of(expr.span, "unreachable").is_some() { - span_lint(cx, UNREACHABLE, span, "usage of the `unreachable!` macro"); - } else if is_expn_of(expr.span, "panic").is_some() { - span_lint(cx, PANIC, span, "`panic` should not be present in production code"); - } - } - } -} - -fn get_outer_span(expr: &Expr<'_>) -> Span { - if_chain! { - if expr.span.from_expansion(); - let first = expr.span.ctxt().outer_expn_data().call_site; - if first.from_expansion(); - then { - first.ctxt().outer_expn_data().call_site - } else { - expr.span + }, + "unreachable" => { + span_lint(cx, UNREACHABLE, macro_call.span, "usage of the `unreachable!` macro"); + }, + _ => {}, } } } diff --git a/clippy_lints/src/unit_types/unit_cmp.rs b/clippy_lints/src/unit_types/unit_cmp.rs index 6d9aff47421..1dd8895ebd0 100644 --- a/clippy_lints/src/unit_types/unit_cmp.rs +++ b/clippy_lints/src/unit_types/unit_cmp.rs @@ -1,35 +1,29 @@ use clippy_utils::diagnostics::span_lint; +use clippy_utils::macros::{find_assert_eq_args, root_macro_call_first_node}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::hygiene::{ExpnKind, MacroKind}; use super::UNIT_CMP; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if expr.span.from_expansion() { - if let Some(callee) = expr.span.source_callee() { - if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { - if let ExprKind::Binary(ref cmp, left, _) = expr.kind { - let op = cmp.node; - if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() { - let result = match symbol.as_str() { - "assert_eq" | "debug_assert_eq" => "succeed", - "assert_ne" | "debug_assert_ne" => "fail", - _ => return, - }; - span_lint( - cx, - UNIT_CMP, - expr.span, - &format!( - "`{}` of unit values detected. This will always {}", - symbol.as_str(), - result - ), - ); - } - } + if let Some(macro_call) = root_macro_call_first_node(cx, expr) { + let macro_name = cx.tcx.item_name(macro_call.def_id); + let result = match macro_name.as_str() { + "assert_eq" | "debug_assert_eq" => "succeed", + "assert_ne" | "debug_assert_ne" => "fail", + _ => return, + }; + let Some ((left, _, _)) = find_assert_eq_args(cx, expr, macro_call.expn) else { return }; + if !cx.typeck_results().expr_ty(left).is_unit() { + return; } + span_lint( + cx, + UNIT_CMP, + macro_call.span, + &format!("`{}` of unit values detected. This will always {}", macro_name, result), + ); } return; } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index e98dcd3cf98..165004e5b41 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,5 +1,6 @@ use clippy_utils::consts::{constant_simple, Constant}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::macros::root_macro_call_first_node; use clippy_utils::source::snippet; use clippy_utils::ty::match_type; use clippy_utils::{ @@ -410,9 +411,13 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } self.declared_lints.insert(item.ident.name, item.span); } - } else if is_expn_of(item.span, "impl_lint_pass").is_some() - || is_expn_of(item.span, "declare_lint_pass").is_some() - { + } else if let Some(macro_call) = root_macro_call_first_node(cx, item) { + if !matches!( + &*cx.tcx.item_name(macro_call.def_id).as_str(), + "impl_lint_pass" | "declare_lint_pass" + ) { + return; + } if let hir::ItemKind::Impl(hir::Impl { of_trait: None, items: impl_item_refs, diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 0ba0b59ed13..af1e2eb4dd1 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" publish = false [dependencies] +arrayvec = { version = "0.7", default-features = false } if_chain = "1.0" rustc-semver = "1.1" diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 8400bfbbd99..3d3180521ab 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -5,7 +5,6 @@ #![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)] use crate::{both, over}; -use if_chain::if_chain; use rustc_ast::ptr::P; use rustc_ast::{self as ast, *}; use rustc_span::symbol::Ident; @@ -679,34 +678,3 @@ pub fn eq_mac_args(l: &MacArgs, r: &MacArgs) -> bool { _ => false, } } - -/// Extract args from an assert-like macro. -/// -/// Currently working with: -/// - `assert_eq!` and `assert_ne!` -/// - `debug_assert_eq!` and `debug_assert_ne!` -/// -/// For example: -/// -/// `debug_assert_eq!(a, b)` will return Some([a, b]) -pub fn extract_assert_macro_args(mut expr: &Expr) -> Option<[&Expr; 2]> { - if_chain! { - if let ExprKind::If(_, ref block, _) = expr.kind; - if let StmtKind::Semi(ref e) = block.stmts.get(0)?.kind; - then { - expr = e; - } - } - if_chain! { - if let ExprKind::Block(ref block, _) = expr.kind; - if let StmtKind::Expr(ref expr) = block.stmts.get(0)?.kind; - if let ExprKind::Match(ref match_expr, _) = expr.kind; - if let ExprKind::Tup(ref tup) = match_expr.kind; - if let [a, b, ..] = tup.as_slice(); - if let (&ExprKind::AddrOf(_, _, ref a), &ExprKind::AddrOf(_, _, ref b)) = (&a.kind, &b.kind); - then { - return Some([&*a, &*b]); - } - } - None -} diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index c764c35d444..160a51740cd 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -3,15 +3,13 @@ #![deny(clippy::missing_docs_in_private_items)] use crate::ty::is_type_diagnostic_item; -use crate::{is_expn_of, last_path_segment, match_def_path, paths}; +use crate::{is_expn_of, match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::{self, LitKind}; use rustc_hir as hir; -use rustc_hir::{ - Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath, StmtKind, UnOp, -}; +use rustc_hir::{Arm, Block, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath}; use rustc_lint::LateContext; -use rustc_span::{sym, symbol, ExpnKind, Span, Symbol}; +use rustc_span::{sym, symbol, Span}; /// The essential nodes of a desugared for loop as well as the entire span: /// `for pat in arg { body }` becomes `(pat, arg, body)`. Return `(pat, arg, body, span)`. @@ -428,293 +426,6 @@ pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind { } } -/// Extract args from an assert-like macro. -/// Currently working with: -/// - `assert!`, `assert_eq!` and `assert_ne!` -/// - `debug_assert!`, `debug_assert_eq!` and `debug_assert_ne!` -/// For example: -/// `assert!(expr)` will return `Some([expr])` -/// `debug_assert_eq!(a, b)` will return `Some([a, b])` -pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option>> { - /// Try to match the AST for a pattern that contains a match, for example when two args are - /// compared - fn ast_matchblock(matchblock_expr: &'tcx Expr<'tcx>) -> Option>> { - if_chain! { - if let ExprKind::Match(headerexpr, _, _) = &matchblock_expr.kind; - if let ExprKind::Tup([lhs, rhs]) = &headerexpr.kind; - if let ExprKind::AddrOf(BorrowKind::Ref, _, lhs) = lhs.kind; - if let ExprKind::AddrOf(BorrowKind::Ref, _, rhs) = rhs.kind; - then { - return Some(vec![lhs, rhs]); - } - } - None - } - - if let ExprKind::Block(block, _) = e.kind { - if block.stmts.len() == 1 { - if let StmtKind::Semi(matchexpr) = block.stmts.get(0)?.kind { - // macros with unique arg: `{debug_}assert!` (e.g., `debug_assert!(some_condition)`) - if_chain! { - if let Some(If { cond, .. }) = If::hir(matchexpr); - if let ExprKind::Unary(UnOp::Not, condition) = cond.kind; - then { - return Some(vec![condition]); - } - } - - // debug macros with two args: `debug_assert_{ne, eq}` (e.g., `assert_ne!(a, b)`) - if_chain! { - if let ExprKind::Block(matchblock,_) = matchexpr.kind; - if let Some(matchblock_expr) = matchblock.expr; - then { - return ast_matchblock(matchblock_expr); - } - } - } - } else if let Some(matchblock_expr) = block.expr { - // macros with two args: `assert_{ne, eq}` (e.g., `assert_ne!(a, b)`) - return ast_matchblock(matchblock_expr); - } - } - None -} - -/// A parsed `format!` expansion -pub struct FormatExpn<'tcx> { - /// Span of `format!(..)` - pub call_site: Span, - /// Inner `format_args!` expansion - pub format_args: FormatArgsExpn<'tcx>, -} - -impl FormatExpn<'tcx> { - /// Parses an expanded `format!` invocation - pub fn parse(expr: &'tcx Expr<'tcx>) -> Option { - if_chain! { - if let ExprKind::Block(block, _) = expr.kind; - if let [stmt] = block.stmts; - if let StmtKind::Local(local) = stmt.kind; - if let Some(init) = local.init; - if let ExprKind::Call(_, [format_args]) = init.kind; - let expn_data = expr.span.ctxt().outer_expn_data(); - if let ExpnKind::Macro(_, sym::format) = expn_data.kind; - if let Some(format_args) = FormatArgsExpn::parse(format_args); - then { - Some(FormatExpn { - call_site: expn_data.call_site, - format_args, - }) - } else { - None - } - } - } -} - -/// A parsed `format_args!` expansion -pub struct FormatArgsExpn<'tcx> { - /// Span of the first argument, the format string - pub format_string_span: Span, - /// Values passed after the format string - pub value_args: Vec<&'tcx Expr<'tcx>>, - - /// String literal expressions which represent the format string split by "{}" - pub format_string_parts: &'tcx [Expr<'tcx>], - /// Symbols corresponding to [`Self::format_string_parts`] - pub format_string_symbols: Vec, - /// Expressions like `ArgumentV1::new(arg0, Debug::fmt)` - pub args: &'tcx [Expr<'tcx>], - /// The final argument passed to `Arguments::new_v1_formatted`, if applicable - pub fmt_expr: Option<&'tcx Expr<'tcx>>, -} - -impl FormatArgsExpn<'tcx> { - /// Parses an expanded `format_args!` or `format_args_nl!` invocation - pub fn parse(expr: &'tcx Expr<'tcx>) -> Option { - if_chain! { - if let ExpnKind::Macro(_, name) = expr.span.ctxt().outer_expn_data().kind; - let name = name.as_str(); - if name.ends_with("format_args") || name.ends_with("format_args_nl"); - if let ExprKind::Call(_, args) = expr.kind; - if let Some((strs_ref, args, fmt_expr)) = match args { - // Arguments::new_v1 - [strs_ref, args] => Some((strs_ref, args, None)), - // Arguments::new_v1_formatted - [strs_ref, args, fmt_expr, _unsafe_arg] => Some((strs_ref, args, Some(fmt_expr))), - _ => None, - }; - if let ExprKind::AddrOf(BorrowKind::Ref, _, strs_arr) = strs_ref.kind; - if let ExprKind::Array(format_string_parts) = strs_arr.kind; - if let Some(format_string_symbols) = format_string_parts - .iter() - .map(|e| { - if let ExprKind::Lit(lit) = &e.kind { - if let LitKind::Str(symbol, _style) = lit.node { - return Some(symbol); - } - } - None - }) - .collect(); - if let ExprKind::AddrOf(BorrowKind::Ref, _, args) = args.kind; - if let ExprKind::Match(args, [arm], _) = args.kind; - if let ExprKind::Tup(value_args) = args.kind; - if let Some(value_args) = value_args - .iter() - .map(|e| match e.kind { - ExprKind::AddrOf(_, _, e) => Some(e), - _ => None, - }) - .collect(); - if let ExprKind::Array(args) = arm.body.kind; - then { - Some(FormatArgsExpn { - format_string_span: strs_ref.span, - value_args, - format_string_parts, - format_string_symbols, - args, - fmt_expr, - }) - } else { - None - } - } - } - - /// Returns a vector of `FormatArgsArg`. - pub fn args(&self) -> Option>> { - if let Some(expr) = self.fmt_expr { - if_chain! { - if let ExprKind::AddrOf(BorrowKind::Ref, _, expr) = expr.kind; - if let ExprKind::Array(exprs) = expr.kind; - then { - exprs.iter().map(|fmt| { - if_chain! { - // struct `core::fmt::rt::v1::Argument` - if let ExprKind::Struct(_, fields, _) = fmt.kind; - if let Some(position_field) = fields.iter().find(|f| f.ident.name == sym::position); - if let ExprKind::Lit(lit) = &position_field.expr.kind; - if let LitKind::Int(position, _) = lit.node; - if let Ok(i) = usize::try_from(position); - let arg = &self.args[i]; - if let ExprKind::Call(_, [arg_name, _]) = arg.kind; - if let ExprKind::Field(_, j) = arg_name.kind; - if let Ok(j) = j.name.as_str().parse::(); - then { - Some(FormatArgsArg { value: self.value_args[j], arg, fmt: Some(fmt) }) - } else { - None - } - } - }).collect() - } else { - None - } - } - } else { - Some( - self.value_args - .iter() - .zip(self.args.iter()) - .map(|(value, arg)| FormatArgsArg { value, arg, fmt: None }) - .collect(), - ) - } - } -} - -/// Type representing a `FormatArgsExpn`'s format arguments -pub struct FormatArgsArg<'tcx> { - /// An element of `value_args` according to `position` - pub value: &'tcx Expr<'tcx>, - /// An element of `args` according to `position` - pub arg: &'tcx Expr<'tcx>, - /// An element of `fmt_expn` - pub fmt: Option<&'tcx Expr<'tcx>>, -} - -impl<'tcx> FormatArgsArg<'tcx> { - /// Returns true if any formatting parameters are used that would have an effect on strings, - /// like `{:+2}` instead of just `{}`. - pub fn has_string_formatting(&self) -> bool { - self.fmt.map_or(false, |fmt| { - // `!` because these conditions check that `self` is unformatted. - !if_chain! { - // struct `core::fmt::rt::v1::Argument` - if let ExprKind::Struct(_, fields, _) = fmt.kind; - if let Some(format_field) = fields.iter().find(|f| f.ident.name == sym::format); - // struct `core::fmt::rt::v1::FormatSpec` - if let ExprKind::Struct(_, subfields, _) = format_field.expr.kind; - let mut precision_found = false; - let mut width_found = false; - if subfields.iter().all(|field| { - match field.ident.name { - sym::precision => { - precision_found = true; - if let ExprKind::Path(ref precision_path) = field.expr.kind { - last_path_segment(precision_path).ident.name == sym::Implied - } else { - false - } - } - sym::width => { - width_found = true; - if let ExprKind::Path(ref width_qpath) = field.expr.kind { - last_path_segment(width_qpath).ident.name == sym::Implied - } else { - false - } - } - _ => true, - } - }); - if precision_found && width_found; - then { true } else { false } - } - }) - } - - /// Returns true if the argument is formatted using `Display::fmt`. - pub fn is_display(&self) -> bool { - if_chain! { - if let ExprKind::Call(_, [_, format_field]) = self.arg.kind; - if let ExprKind::Path(QPath::Resolved(_, path)) = format_field.kind; - if let [.., t, _] = path.segments; - if t.ident.name == sym::Display; - then { true } else { false } - } - } -} - -/// A parsed `panic!` expansion -pub struct PanicExpn<'tcx> { - /// Span of `panic!(..)` - pub call_site: Span, - /// Inner `format_args!` expansion - pub format_args: FormatArgsExpn<'tcx>, -} - -impl PanicExpn<'tcx> { - /// Parses an expanded `panic!` invocation - pub fn parse(expr: &'tcx Expr<'tcx>) -> Option { - if_chain! { - if let ExprKind::Call(_, [format_args]) = expr.kind; - let expn_data = expr.span.ctxt().outer_expn_data(); - if let Some(format_args) = FormatArgsExpn::parse(format_args); - then { - Some(PanicExpn { - call_site: expn_data.call_site, - format_args, - }) - } else { - None - } - } - } -} - /// A parsed `Vec` initialization expression #[derive(Clone, Copy)] pub enum VecInitKind { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 54d470ca738..bbb70e3adb5 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -44,6 +44,7 @@ pub mod diagnostics; pub mod eager_or_lazy; pub mod higher; mod hir_utils; +pub mod macros; pub mod msrvs; pub mod numeric_literal; pub mod paths; @@ -1138,19 +1139,6 @@ pub fn contains_return(expr: &hir::Expr<'_>) -> bool { found } -/// Finds calls of the specified macros in a function body. -pub fn find_macro_calls(names: &[&str], body: &Body<'_>) -> Vec { - let mut result = Vec::new(); - expr_visitor_no_bodies(|expr| { - if names.iter().any(|fun| is_expn_of(expr.span, fun).is_some()) { - result.push(expr.span); - } - true - }) - .visit_expr(&body.value); - result -} - /// Extends the span to the beginning of the spans line, incl. whitespaces. /// /// ```rust @@ -1679,32 +1667,6 @@ pub fn match_libc_symbol(cx: &LateContext<'_>, did: DefId, name: &str) -> bool { path.first().map_or(false, |s| s.as_str() == "libc") && path.last().map_or(false, |s| s.as_str() == name) } -pub fn match_panic_call(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if let ExprKind::Call(func, [arg]) = expr.kind { - expr_path_res(cx, func) - .opt_def_id() - .map_or(false, |id| match_panic_def_id(cx, id)) - .then(|| arg) - } else { - None - } -} - -pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool { - match_any_def_paths( - cx, - did, - &[ - &paths::BEGIN_PANIC, - &paths::PANIC_ANY, - &paths::PANICKING_PANIC, - &paths::PANICKING_PANIC_FMT, - &paths::PANICKING_PANIC_STR, - ], - ) - .is_some() -} - /// Returns the list of condition expressions and the list of blocks in a /// sequence of `if/else`. /// E.g., this returns `([a, b], [c, d, e])` for the expression diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs new file mode 100644 index 00000000000..2bf43aeb995 --- /dev/null +++ b/clippy_utils/src/macros.rs @@ -0,0 +1,539 @@ +#![allow(clippy::similar_names)] // `expr` and `expn` + +use crate::visitors::expr_visitor_no_bodies; + +use arrayvec::ArrayVec; +use if_chain::if_chain; +use rustc_ast::ast::LitKind; +use rustc_hir::intravisit::Visitor; +use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath}; +use rustc_lint::LateContext; +use rustc_span::def_id::DefId; +use rustc_span::hygiene::{MacroKind, SyntaxContext}; +use rustc_span::{sym, ExpnData, ExpnId, ExpnKind, Span, Symbol}; +use std::ops::ControlFlow; + +/// A macro call, like `vec![1, 2, 3]`. +/// +/// Use `tcx.item_name(macro_call.def_id)` to get the macro name. +/// Even better is to check if it is a diagnostic item. +/// +/// This structure is similar to `ExpnData` but it precludes desugaring expansions. +#[derive(Debug)] +pub struct MacroCall { + /// Macro `DefId` + pub def_id: DefId, + /// Kind of macro + pub kind: MacroKind, + /// The expansion produced by the macro call + pub expn: ExpnId, + /// Span of the macro call site + pub span: Span, +} + +impl MacroCall { + pub fn is_local(&self) -> bool { + span_is_local(self.span) + } +} + +/// Returns an iterator of expansions that created the given span +pub fn expn_backtrace(mut span: Span) -> impl Iterator { + std::iter::from_fn(move || { + let ctxt = span.ctxt(); + if ctxt == SyntaxContext::root() { + return None; + } + let expn = ctxt.outer_expn(); + let data = expn.expn_data(); + span = data.call_site; + Some((expn, data)) + }) +} + +/// Checks whether the span is from the root expansion or a locally defined macro +pub fn span_is_local(span: Span) -> bool { + !span.from_expansion() || expn_is_local(span.ctxt().outer_expn()) +} + +/// Checks whether the expansion is the root expansion or a locally defined macro +pub fn expn_is_local(expn: ExpnId) -> bool { + if expn == ExpnId::root() { + return true; + } + let data = expn.expn_data(); + let backtrace = expn_backtrace(data.call_site); + std::iter::once((expn, data)) + .chain(backtrace) + .find_map(|(_, data)| data.macro_def_id) + .map_or(true, DefId::is_local) +} + +/// Returns an iterator of macro expansions that created the given span. +/// Note that desugaring expansions are skipped. +pub fn macro_backtrace(span: Span) -> impl Iterator { + expn_backtrace(span).filter_map(|(expn, data)| match data { + ExpnData { + kind: ExpnKind::Macro(kind, _), + macro_def_id: Some(def_id), + call_site: span, + .. + } => Some(MacroCall { + def_id, + kind, + expn, + span, + }), + _ => None, + }) +} + +/// If the macro backtrace of `span` has a macro call at the root expansion +/// (i.e. not a nested macro call), returns `Some` with the `MacroCall` +pub fn root_macro_call(span: Span) -> Option { + macro_backtrace(span).last() +} + +/// Like [`root_macro_call`], but only returns `Some` if `node` is the "first node" +/// produced by the macro call, as in [`first_node_in_macro`]. +pub fn root_macro_call_first_node(cx: &LateContext<'_>, node: &impl HirNode) -> Option { + if first_node_in_macro(cx, node) != Some(ExpnId::root()) { + return None; + } + root_macro_call(node.span()) +} + +/// Like [`macro_backtrace`], but only returns macro calls where `node` is the "first node" of the +/// macro call, as in [`first_node_in_macro`]. +pub fn first_node_macro_backtrace(cx: &LateContext<'_>, node: &impl HirNode) -> impl Iterator { + let span = node.span(); + first_node_in_macro(cx, node) + .into_iter() + .flat_map(move |expn| macro_backtrace(span).take_while(move |macro_call| macro_call.expn != expn)) +} + +/// If `node` is the "first node" in a macro expansion, returns `Some` with the `ExpnId` of the +/// macro call site (i.e. the parent of the macro expansion). This generally means that `node` +/// is the outermost node of an entire macro expansion, but there are some caveats noted below. +/// This is useful for finding macro calls while visiting the HIR without processing the macro call +/// at every node within its expansion. +/// +/// If you already have immediate access to the parent node, it is simpler to +/// just check the context of that span directly (e.g. `parent.span.from_expansion()`). +/// +/// If a macro call is in statement position, it expands to one or more statements. +/// In that case, each statement *and* their immediate descendants will all yield `Some` +/// with the `ExpnId` of the containing block. +/// +/// A node may be the "first node" of multiple macro calls in a macro backtrace. +/// The expansion of the outermost macro call site is returned in such cases. +pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option { + // get the macro expansion or return `None` if not found + // `macro_backtrace` importantly ignores desugaring expansions + let expn = macro_backtrace(node.span()).next()?.expn; + + // get the parent node, possibly skipping over a statement + // if the parent is not found, it is sensible to return `Some(root)` + let hir = cx.tcx.hir(); + let mut parent_iter = hir.parent_iter(node.hir_id()); + let (parent_id, _) = match parent_iter.next() { + None => return Some(ExpnId::root()), + Some((_, Node::Stmt(_))) => match parent_iter.next() { + None => return Some(ExpnId::root()), + Some(next) => next, + }, + Some(next) => next, + }; + + // get the macro expansion of the parent node + let parent_span = hir.span(parent_id); + let Some(parent_macro_call) = macro_backtrace(parent_span).next() else { + // the parent node is not in a macro + return Some(ExpnId::root()); + }; + + if parent_macro_call.expn.is_descendant_of(expn) { + // `node` is input to a macro call + return None; + } + + Some(parent_macro_call.expn) +} + +/* Specific Macro Utils */ + +/// Is `def_id` of `std::panic`, `core::panic` or any inner implementation macros +pub fn is_panic(cx: &LateContext<'_>, def_id: DefId) -> bool { + let Some(name) = cx.tcx.get_diagnostic_name(def_id) else { return false }; + matches!( + name.as_str(), + "core_panic_macro" + | "std_panic_macro" + | "core_panic_2015_macro" + | "std_panic_2015_macro" + | "core_panic_2021_macro" + ) +} + +pub enum PanicExpn<'a> { + /// No arguments - `panic!()` + Empty, + /// A string literal or any `&str` - `panic!("message")` or `panic!(message)` + Str(&'a Expr<'a>), + /// A single argument that implements `Display` - `panic!("{}", object)` + Display(&'a Expr<'a>), + /// Anything else - `panic!("error {}: {}", a, b)` + Format(FormatArgsExpn<'a>), +} + +impl<'a> PanicExpn<'a> { + pub fn parse(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option { + if !macro_backtrace(expr.span).any(|macro_call| is_panic(cx, macro_call.def_id)) { + return None; + } + let ExprKind::Call(callee, [arg]) = expr.kind else { return None }; + let ExprKind::Path(QPath::Resolved(_, path)) = callee.kind else { return None }; + let result = match path.segments.last().unwrap().ident.as_str() { + "panic" if arg.span.ctxt() == expr.span.ctxt() => Self::Empty, + "panic" | "panic_str" => Self::Str(arg), + "panic_display" => { + let ExprKind::AddrOf(_, _, e) = arg.kind else { return None }; + Self::Display(e) + }, + "panic_fmt" => Self::Format(FormatArgsExpn::parse(cx, arg)?), + _ => return None, + }; + Some(result) + } +} + +/// Finds the arguments of an `assert!` or `debug_assert!` macro call within the macro expansion +pub fn find_assert_args<'a>( + cx: &LateContext<'_>, + expr: &'a Expr<'a>, + expn: ExpnId, +) -> Option<(&'a Expr<'a>, PanicExpn<'a>)> { + find_assert_args_inner(cx, expr, expn).map(|([e], p)| (e, p)) +} + +/// Finds the arguments of an `assert_eq!` or `debug_assert_eq!` macro call within the macro +/// expansion +pub fn find_assert_eq_args<'a>( + cx: &LateContext<'_>, + expr: &'a Expr<'a>, + expn: ExpnId, +) -> Option<(&'a Expr<'a>, &'a Expr<'a>, PanicExpn<'a>)> { + find_assert_args_inner(cx, expr, expn).map(|([a, b], p)| (a, b, p)) +} + +fn find_assert_args_inner<'a, const N: usize>( + cx: &LateContext<'_>, + expr: &'a Expr<'a>, + expn: ExpnId, +) -> Option<([&'a Expr<'a>; N], PanicExpn<'a>)> { + let macro_id = expn.expn_data().macro_def_id?; + let (expr, expn) = match cx.tcx.item_name(macro_id).as_str().strip_prefix("debug_") { + None => (expr, expn), + Some(inner_name) => find_assert_within_debug_assert(cx, expr, expn, Symbol::intern(inner_name))?, + }; + let mut args = ArrayVec::new(); + let mut panic_expn = None; + expr_visitor_no_bodies(|e| { + if args.is_full() { + if panic_expn.is_none() && e.span.ctxt() != expr.span.ctxt() { + panic_expn = PanicExpn::parse(cx, e); + } + panic_expn.is_none() + } else if is_assert_arg(cx, e, expn) { + args.push(e); + false + } else { + true + } + }) + .visit_expr(expr); + let args = args.into_inner().ok()?; + // if no `panic!(..)` is found, use `PanicExpn::Empty` + // to indicate that the default assertion message is used + let panic_expn = panic_expn.unwrap_or(PanicExpn::Empty); + Some((args, panic_expn)) +} + +fn find_assert_within_debug_assert<'a>( + cx: &LateContext<'_>, + expr: &'a Expr<'a>, + expn: ExpnId, + assert_name: Symbol, +) -> Option<(&'a Expr<'a>, ExpnId)> { + let mut found = None; + expr_visitor_no_bodies(|e| { + if found.is_some() || !e.span.from_expansion() { + return false; + } + let e_expn = e.span.ctxt().outer_expn(); + if e_expn == expn { + return true; + } + if e_expn.expn_data().macro_def_id.map(|id| cx.tcx.item_name(id)) == Some(assert_name) { + found = Some((e, e_expn)); + } + false + }) + .visit_expr(expr); + found +} + +fn is_assert_arg(cx: &LateContext<'_>, expr: &'a Expr<'a>, assert_expn: ExpnId) -> bool { + if !expr.span.from_expansion() { + return true; + } + let result = macro_backtrace(expr.span).try_for_each(|macro_call| { + if macro_call.expn == assert_expn { + ControlFlow::Break(false) + } else { + match cx.tcx.item_name(macro_call.def_id) { + // `cfg!(debug_assertions)` in `debug_assert!` + sym::cfg => ControlFlow::CONTINUE, + // assert!(other_macro!(..)) + _ => ControlFlow::Break(true), + } + } + }); + match result { + ControlFlow::Break(is_assert_arg) => is_assert_arg, + ControlFlow::Continue(()) => true, + } +} + +/// A parsed `format_args!` expansion +pub struct FormatArgsExpn<'tcx> { + /// Span of the first argument, the format string + pub format_string_span: Span, + /// The format string split by formatted args like `{..}` + pub format_string_parts: Vec, + /// Values passed after the format string + pub value_args: Vec<&'tcx Expr<'tcx>>, + /// Each element is a `value_args` index and a formatting trait (e.g. `sym::Debug`) + pub formatters: Vec<(usize, Symbol)>, + /// List of `fmt::v1::Argument { .. }` expressions. If this is empty, + /// then `formatters` represents the format args (`{..}`). + /// If this is non-empty, it represents the format args, and the `position` + /// parameters within the struct expressions are indexes of `formatters`. + pub specs: Vec<&'tcx Expr<'tcx>>, +} + +impl FormatArgsExpn<'tcx> { + /// Parses an expanded `format_args!` or `format_args_nl!` invocation + pub fn parse(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option { + macro_backtrace(expr.span).find(|macro_call| { + matches!( + cx.tcx.item_name(macro_call.def_id), + sym::const_format_args | sym::format_args | sym::format_args_nl + ) + })?; + let mut format_string_span: Option = None; + let mut format_string_parts: Vec = Vec::new(); + let mut value_args: Vec<&Expr<'_>> = Vec::new(); + let mut formatters: Vec<(usize, Symbol)> = Vec::new(); + let mut specs: Vec<&Expr<'_>> = Vec::new(); + expr_visitor_no_bodies(|e| { + // if we're still inside of the macro definition... + if e.span.ctxt() == expr.span.ctxt() { + // ArgumnetV1::new(, ::fmt) + if_chain! { + if let ExprKind::Call(callee, [val, fmt_path]) = e.kind; + if let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind; + if seg.ident.name == sym::new; + if let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind; + if path.segments.last().unwrap().ident.name == sym::ArgumentV1; + if let ExprKind::Path(QPath::Resolved(_, path)) = fmt_path.kind; + if let [.., fmt_trait, _fmt] = path.segments; + then { + let val_idx = if_chain! { + if val.span.ctxt() == expr.span.ctxt(); + if let ExprKind::Field(_, field) = val.kind; + if let Ok(idx) = field.name.as_str().parse(); + then { + // tuple index + idx + } else { + // assume the value expression is passed directly + formatters.len() + } + }; + formatters.push((val_idx, fmt_trait.ident.name)); + } + } + if let ExprKind::Struct(QPath::Resolved(_, path), ..) = e.kind { + if path.segments.last().unwrap().ident.name == sym::Argument { + specs.push(e); + } + } + // walk through the macro expansion + return true; + } + // assume that the first expr with a differing context represents + // (and has the span of) the format string + if format_string_span.is_none() { + format_string_span = Some(e.span); + let span = e.span; + // walk the expr and collect string literals which are format string parts + expr_visitor_no_bodies(|e| { + if e.span.ctxt() != span.ctxt() { + // defensive check, probably doesn't happen + return false; + } + if let ExprKind::Lit(lit) = &e.kind { + if let LitKind::Str(symbol, _s) = lit.node { + format_string_parts.push(symbol); + } + } + true + }) + .visit_expr(e); + } else { + // assume that any further exprs with a differing context are value args + value_args.push(e); + } + // don't walk anything not from the macro expansion (e.a. inputs) + false + }) + .visit_expr(expr); + Some(FormatArgsExpn { + format_string_span: format_string_span?, + format_string_parts, + value_args, + formatters, + specs, + }) + } + + /// Finds a nested call to `format_args!` within a `format!`-like macro call + pub fn find_nested(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, expn_id: ExpnId) -> Option { + let mut format_args = None; + expr_visitor_no_bodies(|e| { + if format_args.is_some() { + return false; + } + let e_ctxt = e.span.ctxt(); + if e_ctxt == expr.span.ctxt() { + return true; + } + if e_ctxt.outer_expn().is_descendant_of(expn_id) { + format_args = FormatArgsExpn::parse(cx, e); + } + false + }) + .visit_expr(expr); + format_args + } + + /// Returns a vector of `FormatArgsArg`. + pub fn args(&self) -> Option>> { + if self.specs.is_empty() { + let args = std::iter::zip(&self.value_args, &self.formatters) + .map(|(value, &(_, format_trait))| FormatArgsArg { + value, + format_trait, + spec: None, + }) + .collect(); + return Some(args); + } + self.specs + .iter() + .map(|spec| { + if_chain! { + // struct `core::fmt::rt::v1::Argument` + if let ExprKind::Struct(_, fields, _) = spec.kind; + if let Some(position_field) = fields.iter().find(|f| f.ident.name == sym::position); + if let ExprKind::Lit(lit) = &position_field.expr.kind; + if let LitKind::Int(position, _) = lit.node; + if let Ok(i) = usize::try_from(position); + if let Some(&(j, format_trait)) = self.formatters.get(i); + then { + Some(FormatArgsArg { value: self.value_args[j], format_trait, spec: Some(spec) }) + } else { + None + } + } + }) + .collect() + } + + /// Span of all inputs + pub fn inputs_span(&self) -> Span { + match *self.value_args { + [] => self.format_string_span, + [.., last] => self.format_string_span.to(last.span), + } + } +} + +/// Type representing a `FormatArgsExpn`'s format arguments +pub struct FormatArgsArg<'tcx> { + /// An element of `value_args` according to `position` + pub value: &'tcx Expr<'tcx>, + /// An element of `args` according to `position` + pub format_trait: Symbol, + /// An element of `specs` + pub spec: Option<&'tcx Expr<'tcx>>, +} + +impl<'tcx> FormatArgsArg<'tcx> { + /// Returns true if any formatting parameters are used that would have an effect on strings, + /// like `{:+2}` instead of just `{}`. + pub fn has_string_formatting(&self) -> bool { + self.spec.map_or(false, |spec| { + // `!` because these conditions check that `self` is unformatted. + !if_chain! { + // struct `core::fmt::rt::v1::Argument` + if let ExprKind::Struct(_, fields, _) = spec.kind; + if let Some(format_field) = fields.iter().find(|f| f.ident.name == sym::format); + // struct `core::fmt::rt::v1::FormatSpec` + if let ExprKind::Struct(_, subfields, _) = format_field.expr.kind; + if subfields.iter().all(|field| match field.ident.name { + sym::precision | sym::width => match field.expr.kind { + ExprKind::Path(QPath::Resolved(_, path)) => { + path.segments.last().unwrap().ident.name == sym::Implied + } + _ => false, + } + _ => true, + }); + then { true } else { false } + } + }) + } +} + +/// A node with a `HirId` and a `Span` +pub trait HirNode { + fn hir_id(&self) -> HirId; + fn span(&self) -> Span; +} + +macro_rules! impl_hir_node { + ($($t:ident),*) => { + $(impl HirNode for hir::$t<'_> { + fn hir_id(&self) -> HirId { + self.hir_id + } + fn span(&self) -> Span { + self.span + } + })* + }; +} + +impl_hir_node!(Expr, Pat); + +impl HirNode for hir::Item<'_> { + fn hir_id(&self) -> HirId { + self.hir_id() + } + + fn span(&self) -> Span { + self.span + } +} diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index aa3b3af2356..27db53a6e6d 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -25,7 +25,6 @@ pub const ASSERT_MACRO: [&str; 4] = ["core", "macros", "builtin", "assert"]; pub const ASSERT_NE_MACRO: [&str; 3] = ["core", "macros", "assert_ne"]; pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"]; pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"]; -pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"]; /// Preferably use the diagnostic item `sym::Borrow` where possible pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"]; pub const BORROW_MUT_TRAIT: [&str; 3] = ["core", "borrow", "BorrowMut"]; @@ -110,10 +109,6 @@ pub const OPTION_SOME: [&str; 4] = ["core", "option", "Option", "Some"]; pub const ORD: [&str; 3] = ["core", "cmp", "Ord"]; pub const OS_STRING_AS_OS_STR: [&str; 5] = ["std", "ffi", "os_str", "OsString", "as_os_str"]; pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"]; -pub(super) const PANICKING_PANIC: [&str; 3] = ["core", "panicking", "panic"]; -pub(super) const PANICKING_PANIC_FMT: [&str; 3] = ["core", "panicking", "panic_fmt"]; -pub(super) const PANICKING_PANIC_STR: [&str; 3] = ["core", "panicking", "panic_str"]; -pub(super) const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"]; pub const PARKING_LOT_RAWMUTEX: [&str; 3] = ["parking_lot", "raw_mutex", "RawMutex"]; pub const PARKING_LOT_RAWRWLOCK: [&str; 3] = ["parking_lot", "raw_rwlock", "RawRwLock"]; pub const PARKING_LOT_MUTEX_GUARD: [&str; 2] = ["parking_lot", "MutexGuard"]; diff --git a/tests/ui/assertions_on_constants.rs b/tests/ui/assertions_on_constants.rs index cb516d0f977..7477c01ca78 100644 --- a/tests/ui/assertions_on_constants.rs +++ b/tests/ui/assertions_on_constants.rs @@ -1,4 +1,3 @@ -//FIXME: suggestions are wrongly expanded, this should be fixed along with #7843 #![allow(non_fmt_panics)] macro_rules! assert_const { diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index ec80ec702fb..e1f818814d5 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -1,75 +1,75 @@ error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:11:5 + --> $DIR/assertions_on_constants.rs:10:5 | LL | assert!(true); | ^^^^^^^^^^^^^ | = note: `-D clippy::assertions-on-constants` implied by `-D warnings` = help: remove it - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:12:5 + --> $DIR/assertions_on_constants.rs:11:5 | LL | assert!(false); | ^^^^^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:13:5 + --> $DIR/assertions_on_constants.rs:12:5 | LL | assert!(true, "true message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: remove it - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `assert!(false, $crate::const_format_args!($($t)+))` should probably be replaced - --> $DIR/assertions_on_constants.rs:14:5 +error: `assert!(false, ..)` should probably be replaced + --> $DIR/assertions_on_constants.rs:13:5 | LL | assert!(false, "false message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: use `panic!($crate::const_format_args!($($t)+))` or `unreachable!($crate::const_format_args!($($t)+))` - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) + = help: use `panic!(..)` or `unreachable!(..)` + +error: `assert!(false, ..)` should probably be replaced + --> $DIR/assertions_on_constants.rs:16:5 + | +LL | assert!(false, "{}", msg.to_uppercase()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:20:5 + --> $DIR/assertions_on_constants.rs:19:5 | LL | assert!(B); | ^^^^^^^^^^ | = help: remove it - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:23:5 + --> $DIR/assertions_on_constants.rs:22:5 | LL | assert!(C); | ^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `assert!(false, $crate::const_format_args!($($t)+))` should probably be replaced - --> $DIR/assertions_on_constants.rs:24:5 +error: `assert!(false, ..)` should probably be replaced + --> $DIR/assertions_on_constants.rs:23:5 | LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^ | - = help: use `panic!($crate::const_format_args!($($t)+))` or `unreachable!($crate::const_format_args!($($t)+))` - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) + = help: use `panic!(..)` or `unreachable!(..)` error: `debug_assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:26:5 + --> $DIR/assertions_on_constants.rs:25:5 | LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^ | = help: remove it - = note: this error originates in the macro `$crate::assert` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/eq_op_macros.stderr b/tests/ui/eq_op_macros.stderr index 885415b42c7..cd9f1826e59 100644 --- a/tests/ui/eq_op_macros.stderr +++ b/tests/ui/eq_op_macros.stderr @@ -21,6 +21,28 @@ LL | assert_in_macro_def!(); | = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) +error: identical args used in this `debug_assert_eq!` macro call + --> $DIR/eq_op_macros.rs:9:26 + | +LL | debug_assert_eq!(a, a); + | ^^^^ +... +LL | assert_in_macro_def!(); + | ---------------------- in this macro invocation + | + = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: identical args used in this `debug_assert_ne!` macro call + --> $DIR/eq_op_macros.rs:10:26 + | +LL | debug_assert_ne!(a, a); + | ^^^^ +... +LL | assert_in_macro_def!(); + | ---------------------- in this macro invocation + | + = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) + error: identical args used in this `assert_eq!` macro call --> $DIR/eq_op_macros.rs:22:16 | @@ -45,28 +67,6 @@ error: identical args used in this `assert_ne!` macro call LL | assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ -error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:9:26 - | -LL | debug_assert_eq!(a, a); - | ^^^^ -... -LL | assert_in_macro_def!(); - | ---------------------- in this macro invocation - | - = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:10:26 - | -LL | debug_assert_ne!(a, a); - | ^^^^ -... -LL | assert_in_macro_def!(); - | ---------------------- in this macro invocation - | - = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) - error: identical args used in this `debug_assert_eq!` macro call --> $DIR/eq_op_macros.rs:38:22 | diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index 8bccbaefe23..91ebd695238 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -27,7 +27,6 @@ note: first possible panic found here | LL | panic!("This function panics") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:17:1 @@ -42,7 +41,6 @@ note: first possible panic found here | LL | todo!() | ^^^^^^^ - = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:22:1 @@ -61,7 +59,6 @@ note: first possible panic found here | LL | panic!() | ^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:31:1 @@ -76,7 +73,6 @@ note: first possible panic found here | LL | if true { unreachable!() } else { panic!() } | ^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:36:1 @@ -92,7 +88,6 @@ note: first possible panic found here | LL | assert_eq!(x, 0); | ^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:42:1 @@ -108,7 +103,6 @@ note: first possible panic found here | LL | assert_ne!(x, 0); | ^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 7 previous errors diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index 78d09b8b210..561503ae54f 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -14,7 +14,6 @@ note: return Err() instead of panicking | LL | panic!("error"); | ^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:11:5 @@ -31,7 +30,6 @@ note: return Err() instead of panicking | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:16:5 @@ -48,7 +46,6 @@ note: return Err() instead of panicking | LL | unreachable!(); | ^^^^^^^^^^^^^^ - = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:21:5 @@ -65,7 +62,6 @@ note: return Err() instead of panicking | LL | todo!("Finish this"); | ^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:52:1 @@ -82,7 +78,6 @@ note: return Err() instead of panicking | LL | panic!("error"); | ^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:67:1 @@ -99,7 +94,6 @@ note: return Err() instead of panicking | LL | todo!("finish main method"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index 7501d6d85ed..b6aa005e7b5 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -15,7 +15,6 @@ note: return Err() instead of panicking | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:13:5 @@ -33,7 +32,6 @@ note: return Err() instead of panicking | LL | assert_eq!(x, 5); | ^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:19:5 @@ -51,7 +49,6 @@ note: return Err() instead of panicking | LL | assert_ne!(x, 1); | ^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 2b607ff5888..bfd1c7a3801 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -25,23 +25,18 @@ LL | todo!(); | ^^^^^^^ | = note: `-D clippy::todo` implied by `-D warnings` - = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:17:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:18:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:24:5 @@ -50,23 +45,18 @@ LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unimplemented` implied by `-D warnings` - = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:25:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:26:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:32:5 @@ -75,23 +65,18 @@ LL | unreachable!(); | ^^^^^^^^^^^^^^ | = note: `-D clippy::unreachable` implied by `-D warnings` - = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:33:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:34:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:40:5 @@ -104,24 +89,18 @@ error: `todo` should not be present in production code | LL | todo!(); | ^^^^^^^ - | - = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:42:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:43:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 16 previous errors diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 2b5a7b348b9..824506a4257 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -33,8 +33,6 @@ LL | | }, LL | | } LL | | ); | |_____^ - | - = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: `debug_assert_eq` of unit values detected. This will always succeed --> $DIR/unit_cmp.rs:32:5 @@ -47,8 +45,6 @@ LL | | }, LL | | } LL | | ); | |_____^ - | - = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert_ne` of unit values detected. This will always fail --> $DIR/unit_cmp.rs:41:5 @@ -61,8 +57,6 @@ LL | | }, LL | | } LL | | ); | |_____^ - | - = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: `debug_assert_ne` of unit values detected. This will always fail --> $DIR/unit_cmp.rs:49:5 @@ -75,8 +69,6 @@ LL | | }, LL | | } LL | | ); | |_____^ - | - = note: this error originates in the macro `$crate::assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors -- cgit 1.4.1-3-g733a5 From 4e5f69cc869f734d39f74a5b0d9250eb5fc101ce Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Fri, 13 May 2022 14:20:25 +0900 Subject: Tweak some words improved representation This PR has implemented improved representation. - Use "lib" instead of "lifb" - Use "triggered" instead of "triggere" - Use "blacklisted_name" instead of "blackisted_name" - Use "stabilization" instead of "stabilisation" - Use "behavior" instead of "behaviour" - Use "target" instead of "tartet" - Use "checked_add" instead of "chcked_add" - Use "anti-pattern" instead of "antipattern" - Use "suggestion" instead of "suggesttion" - Use "example" instead of "exampel" - Use "Cheat Sheet" instead of "Cheatsheet" --- clippy_dev/src/main.rs | 2 +- clippy_dev/src/new_lint.rs | 4 ++-- clippy_lints/src/assign_ops.rs | 2 +- clippy_lints/src/casts/cast_slice_different_sizes.rs | 2 +- clippy_lints/src/casts/mod.rs | 2 +- clippy_lints/src/default_union_representation.rs | 4 ++-- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/main_recursion.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/mutable_debug_assertion.rs | 2 +- clippy_lints/src/needless_bitwise_bool.rs | 4 ++-- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/transmute/mod.rs | 4 ++-- doc/adding_lints.md | 4 ++-- tests/ui/blacklisted_name.rs | 4 ++-- 16 files changed, 23 insertions(+), 23 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index dcfaabbc204..d5cd7ca96c0 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -124,7 +124,7 @@ fn get_clap_config<'a>() -> ArgMatches<'a> { * the lint count in README.md is correct\n \ * the changelog contains markdown link references at the bottom\n \ * all lint groups include the correct lints\n \ - * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \ + * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \ * all lints are registered in the lint store", ) .arg(Arg::with_name("print-only").long("print-only").help( diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index 10f67d301f8..07d19638788 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -133,7 +133,7 @@ fn to_camel_case(name: &str) -> String { .collect() } -fn get_stabilisation_version() -> String { +fn get_stabilization_version() -> String { fn parse_manifest(contents: &str) -> Option { let version = contents .lines() @@ -199,7 +199,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { }, }; - let version = get_stabilisation_version(); + let version = get_stabilization_version(); let lint_name = lint.name; let category = lint.category; let name_camel = to_camel_case(lint.name); diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 12c1bddf79d..4c2d3366483 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -50,7 +50,7 @@ declare_clippy_lint! { /// ### Known problems /// Clippy cannot know for sure if `a op= a op b` should have /// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore, it suggests both. - /// If `a op= a op b` is really the correct behaviour it should be + /// If `a op= a op b` is really the correct behavior it should be /// written as `a = a op a op b` as it's less confusing. /// /// ### Example diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index bb09a6708a0..027c660ce3b 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -121,7 +121,7 @@ fn expr_cast_chain_tys<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Optio let to_slice_ty = get_raw_slice_ty_mut(cast_to)?; // If the expression that makes up the source of this cast is itself a cast, recursively - // call `expr_cast_chain_tys` and update the end type with the final tartet type. + // call `expr_cast_chain_tys` and update the end type with the final target type. // Otherwise, this cast is not immediately nested, just construct the info for this cast if let Some(prev_info) = expr_cast_chain_tys(cx, cast_expr) { Some(CastChainInfo { diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index 108e119c104..daf3b7b4ce4 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -306,7 +306,7 @@ declare_clippy_lint! { /// Checks for casts of `&T` to `&mut T` anywhere in the code. /// /// ### Why is this bad? - /// It’s basically guaranteed to be undefined behaviour. + /// It’s basically guaranteed to be undefined behavior. /// `UnsafeCell` is the only way to obtain aliasable data that is considered /// mutable. /// diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index 9b5da0bd8a6..d559ad423df 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -25,7 +25,7 @@ declare_clippy_lint! { /// /// fn main() { /// let _x: u32 = unsafe { - /// Foo { a: 0_i32 }.b // Undefined behaviour: `b` is allowed to be padding + /// Foo { a: 0_i32 }.b // Undefined behavior: `b` is allowed to be padding /// }; /// } /// ``` @@ -39,7 +39,7 @@ declare_clippy_lint! { /// /// fn main() { /// let _x: u32 = unsafe { - /// Foo { a: 0_i32 }.b // Now defined behaviour, this is just an i32 -> u32 transmute + /// Foo { a: 0_i32 }.b // Now defined behavior, this is just an i32 -> u32 transmute /// }; /// } /// ``` diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index a4757ebd8c7..fbbc5bf78a5 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -102,8 +102,8 @@ declare_clippy_lint! { /// types. /// /// ### Why is this bad? - /// To avoid surprising behaviour, these traits should - /// agree and the behaviour of `Copy` cannot be overridden. In almost all + /// To avoid surprising behavior, these traits should + /// agree and the behavior of `Copy` cannot be overridden. In almost all /// situations a `Copy` type should have a `Clone` implementation that does /// nothing more than copy the object, which is what `#[derive(Copy, Clone)]` /// gets you. diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index fad8fa467d4..20333c150e3 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -12,7 +12,7 @@ declare_clippy_lint! { /// /// ### Why is this bad? /// Apart from special setups (which we could detect following attributes like #![no_std]), - /// recursing into main() seems like an unintuitive antipattern we should be able to detect. + /// recursing into main() seems like an unintuitive anti-pattern we should be able to detect. /// /// ### Example /// ```no_run diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 3e07961fcb3..35fc452ed7c 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1563,7 +1563,7 @@ declare_clippy_lint! { #[clippy::version = "1.39.0"] pub MANUAL_SATURATING_ARITHMETIC, style, - "`.chcked_add/sub(x).unwrap_or(MAX/MIN)`" + "`.checked_add/sub(x).unwrap_or(MAX/MIN)`" } declare_clippy_lint! { diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 4ba68c8eacd..8dba60f3a58 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -16,7 +16,7 @@ declare_clippy_lint! { /// ### Why is this bad? /// In release builds `debug_assert!` macros are optimized out by the /// compiler. - /// Therefore mutating something in a `debug_assert!` macro results in different behaviour + /// Therefore mutating something in a `debug_assert!` macro results in different behavior /// between a release and debug build. /// /// ### Example diff --git a/clippy_lints/src/needless_bitwise_bool.rs b/clippy_lints/src/needless_bitwise_bool.rs index 95395e2e136..623d22bc9bd 100644 --- a/clippy_lints/src/needless_bitwise_bool.rs +++ b/clippy_lints/src/needless_bitwise_bool.rs @@ -53,7 +53,7 @@ fn is_bitwise_operation(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { false } -fn suggesstion_snippet(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { +fn suggestion_snippet(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if let ExprKind::Binary(ref op, left, right) = expr.kind { if let (Some(l_snippet), Some(r_snippet)) = (snippet_opt(cx, left.span), snippet_opt(cx, right.span)) { let op_snippet = match op.node { @@ -75,7 +75,7 @@ impl LateLintPass<'_> for NeedlessBitwiseBool { expr.span, "use of bitwise operator instead of lazy operator between booleans", |diag| { - if let Some(sugg) = suggesstion_snippet(cx, expr) { + if let Some(sugg) = suggestion_snippet(cx, expr) { diag.span_suggestion(expr.span, "try", sugg, Applicability::MachineApplicable); } }, diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index c5b8b8103a1..e3ded716341 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -52,7 +52,7 @@ declare_clippy_lint! { /// to a function that needs the memory address. For further details, refer to /// [this issue](https://github.com/rust-lang/rust-clippy/issues/5953) /// that explains a real case in which this false positive - /// led to an **undefined behaviour** introduced with unsafe code. + /// led to an **undefined behavior** introduced with unsafe code. /// /// ### Example /// diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 9904617353f..b19f9aff611 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -632,7 +632,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { } /// Collect possible borrowed for every `&mut` local. -/// For exampel, `_1 = &mut _2` generate _1: {_2,...} +/// For example, `_1 = &mut _2` generate _1: {_2,...} /// Known Problems: not sure all borrowed are tracked struct PossibleOriginVisitor<'a, 'tcx> { possible_origin: TransitiveRelation, diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 342f23f030c..d2a040beb0c 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -27,7 +27,7 @@ declare_clippy_lint! { /// architecture. /// /// ### Why is this bad? - /// It's basically guaranteed to be undefined behaviour. + /// It's basically guaranteed to be undefined behavior. /// /// ### Known problems /// When accessing C, users might want to store pointer @@ -40,7 +40,7 @@ declare_clippy_lint! { #[clippy::version = "pre 1.29.0"] pub WRONG_TRANSMUTE, correctness, - "transmutes that are confusing at best, undefined behaviour at worst and always useless" + "transmutes that are confusing at best, undefined behavior at worst and always useless" } // FIXME: Move this to `complexity` again, after #5343 is fixed diff --git a/doc/adding_lints.md b/doc/adding_lints.md index 4dc94d9f5a5..e8f0c338fd5 100644 --- a/doc/adding_lints.md +++ b/doc/adding_lints.md @@ -28,7 +28,7 @@ because that's clearly a non-descriptive name. - [Debugging](#debugging) - [PR Checklist](#pr-checklist) - [Adding configuration to a lint](#adding-configuration-to-a-lint) - - [Cheatsheet](#cheatsheet) + - [Cheat Sheet](#cheat-sheet) ## Setup @@ -649,7 +649,7 @@ in the following steps: with the configuration value and a rust file that should be linted by Clippy. The test can otherwise be written as usual. -## Cheatsheet +## Cheat Sheet Here are some pointers to things you are likely going to need for every lint: diff --git a/tests/ui/blacklisted_name.rs b/tests/ui/blacklisted_name.rs index 57d7139fef5..27df732a088 100644 --- a/tests/ui/blacklisted_name.rs +++ b/tests/ui/blacklisted_name.rs @@ -46,10 +46,10 @@ fn issue_1647_ref_mut() { mod tests { fn issue_7305() { - // `blackisted_name` lint should not be triggered inside of the test code. + // `blacklisted_name` lint should not be triggered inside of the test code. let foo = 0; - // Check that even in nested functions warning is still not triggere. + // Check that even in nested functions warning is still not triggered. fn nested() { let foo = 0; } -- cgit 1.4.1-3-g733a5 From b20f95c1a1780934367a019a6adba4ec74895716 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Wed, 1 Jun 2022 18:36:02 -0400 Subject: Combine doc examples --- clippy_lints/src/as_conversions.rs | 7 +- clippy_lints/src/attrs.rs | 6 +- clippy_lints/src/blocks_in_if_conditions.rs | 12 ++-- clippy_lints/src/double_parens.rs | 14 ++-- clippy_lints/src/eq_op.rs | 6 +- clippy_lints/src/loops/mod.rs | 15 ++--- clippy_lints/src/methods/mod.rs | 99 ++++++++++++----------------- clippy_lints/src/minmax.rs | 8 +-- clippy_lints/src/misc.rs | 14 ++-- clippy_lints/src/mutable_debug_assertion.rs | 7 +- clippy_lints/src/trait_bounds.rs | 10 +-- 11 files changed, 88 insertions(+), 110 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index 5fa8934c71b..6e5c8f44581 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -32,12 +32,11 @@ declare_clippy_lint! { /// Use instead: /// ```rust,ignore /// f(a.try_into()?); - /// ``` - /// or - /// ```rust,ignore + /// + /// // or + /// /// f(a.try_into().expect("Unexpected u16 overflow in f")); /// ``` - /// #[clippy::version = "1.41.0"] pub AS_CONVERSIONS, restriction, diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 79a5b670fc8..770cb6a3d7b 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -241,13 +241,13 @@ declare_clippy_lint! { /// /// Use instead: /// ```rust + /// # mod hidden { /// #[cfg(target_os = "linux")] /// fn conditional() { } - /// ``` + /// # } /// - /// or + /// // or /// - /// ```rust /// #[cfg(unix)] /// fn conditional() { } /// ``` diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 86e28ea7f7a..5bd7a342389 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -22,21 +22,17 @@ declare_clippy_lint! { /// /// ### Examples /// ```rust - /// // Bad + /// # fn somefunc() -> bool { true }; /// if { true } { /* ... */ } /// - /// // Good - /// if true { /* ... */ } + /// if { let x = somefunc(); x } { /* ... */ } /// ``` /// - /// or - /// + /// Use instead: /// ```rust /// # fn somefunc() -> bool { true }; - /// // Bad - /// if { let x = somefunc(); x } { /* ... */ } + /// if true { /* ... */ } /// - /// // Good /// let res = { let x = somefunc(); x }; /// if res { /* ... */ } /// ``` diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index e10f740d24a..a33ef5ce6e3 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -13,23 +13,21 @@ declare_clippy_lint! { /// /// ### Example /// ```rust - /// // Bad /// fn simple_double_parens() -> i32 { /// ((0)) /// } /// - /// // Good + /// # fn foo(bar: usize) {} + /// foo((0)); + /// ``` + /// + /// Use instead: + /// ```rust /// fn simple_no_parens() -> i32 { /// 0 /// } /// - /// // or - /// /// # fn foo(bar: usize) {} - /// // Bad - /// foo((0)); - /// - /// // Good /// foo(0); /// ``` #[clippy::version = "pre 1.29.0"] diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index afb5d32f953..c3176d987c6 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -30,9 +30,9 @@ declare_clippy_lint! { /// ```rust /// # let x = 1; /// if x + 1 == x + 1 {} - /// ``` - /// or - /// ```rust + /// + /// // or + /// /// # let a = 3; /// # let b = 4; /// assert_eq!(a, a); diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 417248e31ae..d61be78895f 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -180,29 +180,24 @@ declare_clippy_lint! { /// ### Example /// ```rust /// # let opt = Some(1); - /// - /// // Bad + /// # let res: Result = Ok(1); /// for x in opt { /// // .. /// } /// - /// // Good - /// if let Some(x) = opt { + /// for x in &res { /// // .. /// } /// ``` /// - /// or - /// + /// Use instead: /// ```rust + /// # let opt = Some(1); /// # let res: Result = Ok(1); - /// - /// // Bad - /// for x in &res { + /// if let Some(x) = opt { /// // .. /// } /// - /// // Good /// if let Ok(x) = res { /// // .. /// } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index eb1bce8c7d2..08c89ceb796 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -194,25 +194,18 @@ declare_clippy_lint! { /// /// ### Examples /// ```rust - /// # let opt = Some(1); - /// - /// // Bad - /// opt.unwrap(); - /// - /// // Good - /// opt.expect("more helpful message"); + /// # let option = Some(1); + /// # let result: Result = Ok(1); + /// option.unwrap(); + /// result.unwrap(); /// ``` /// - /// or - /// + /// Use instead: /// ```rust - /// # let res: Result = Ok(1); - /// - /// // Bad - /// res.unwrap(); - /// - /// // Good - /// res.expect("more helpful message"); + /// # let option = Some(1); + /// # let result: Result = Ok(1); + /// option.expect("more helpful message"); + /// result.expect("more helpful message"); /// ``` #[clippy::version = "1.45.0"] pub UNWRAP_USED, @@ -235,27 +228,21 @@ declare_clippy_lint! { /// /// ### Examples /// ```rust,ignore - /// # let opt = Some(1); - /// - /// // Bad - /// opt.expect("one"); - /// - /// // Good - /// let opt = Some(1); - /// opt?; + /// # let option = Some(1); + /// # let result: Result = Ok(1); + /// option.expect("one"); + /// result.expect("one"); /// ``` /// - /// or - /// - /// ```rust - /// # let res: Result = Ok(1); + /// Use instead: + /// ```rust,ignore + /// # let option = Some(1); + /// # let result: Result = Ok(1); + /// option?; /// - /// // Bad - /// res.expect("one"); + /// // or /// - /// // Good - /// res?; - /// # Ok::<(), ()>(()) + /// result?; /// ``` #[clippy::version = "1.45.0"] pub EXPECT_USED, @@ -431,26 +418,20 @@ declare_clippy_lint! { /// /// ### Examples /// ```rust - /// # let x = Some(1); - /// - /// // Bad - /// x.map(|a| a + 1).unwrap_or(0); - /// - /// // Good - /// x.map_or(0, |a| a + 1); + /// # let option = Some(1); + /// # let result: Result = Ok(1); + /// # fn some_function(foo: ()) -> usize { 1 } + /// option.map(|a| a + 1).unwrap_or(0); + /// result.map(|a| a + 1).unwrap_or_else(some_function); /// ``` /// - /// or - /// + /// Use instead: /// ```rust - /// # let x: Result = Ok(1); + /// # let option = Some(1); + /// # let result: Result = Ok(1); /// # fn some_function(foo: ()) -> usize { 1 } - /// - /// // Bad - /// x.map(|a| a + 1).unwrap_or_else(some_function); - /// - /// // Good - /// x.map_or_else(some_function, |a| a + 1); + /// option.map_or(0, |a| a + 1); + /// result.map_or_else(some_function, |a| a + 1); /// ``` #[clippy::version = "1.45.0"] pub MAP_UNWRAP_OR, @@ -793,13 +774,14 @@ declare_clippy_lint! { /// # let foo = Some(String::new()); /// foo.unwrap_or(String::new()); /// ``` - /// this can instead be written: + /// + /// Use instead: /// ```rust /// # let foo = Some(String::new()); /// foo.unwrap_or_else(String::new); - /// ``` - /// or - /// ```rust + /// + /// // or + /// /// # let foo = Some(String::new()); /// foo.unwrap_or_default(); /// ``` @@ -863,15 +845,14 @@ declare_clippy_lint! { /// # let err_code = "418"; /// # let err_msg = "I'm a teapot"; /// foo.expect(&format!("Err {}: {}", err_code, err_msg)); - /// ``` - /// or - /// ```rust + /// + /// // or + /// /// # let foo = Some(String::new()); - /// # let err_code = "418"; - /// # let err_msg = "I'm a teapot"; /// foo.expect(format!("Err {}: {}", err_code, err_msg).as_str()); /// ``` - /// this can instead be written: + /// + /// Use instead: /// ```rust /// # let foo = Some(String::new()); /// # let err_code = "418"; diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 65d1f440b76..a081cde8572 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -18,11 +18,11 @@ declare_clippy_lint! { /// the least it hurts readability of the code. /// /// ### Example - /// ```ignore + /// ```rust,ignore /// min(0, max(100, x)) - /// ``` - /// or - /// ```ignore + /// + /// // or + /// /// x.max(100).min(0) /// ``` /// It will always be equal to `0`. Probably the author meant to clamp the value diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 7fdc28c5a06..55665699453 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -103,11 +103,14 @@ declare_clippy_lint! { /// let x = 1.2331f64; /// let y = 1.2332f64; /// - /// // Bad /// if y == 1.23f64 { } /// if y != x {} // where both are floats + /// ``` /// - /// // Good + /// Use instead: + /// ```rust + /// # let x = 1.2331f64; + /// # let y = 1.2332f64; /// let error_margin = f64::EPSILON; // Use an epsilon for comparison /// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead. /// // let error_margin = std::f64::EPSILON; @@ -258,10 +261,13 @@ declare_clippy_lint! { /// let x: f64 = 1.0; /// const ONE: f64 = 1.00; /// - /// // Bad /// if x == ONE { } // where both are floats + /// ``` /// - /// // Good + /// Use instead: + /// ```rust + /// # let x: f64 = 1.0; + /// # const ONE: f64 = 1.00; /// let error_margin = f64::EPSILON; // Use an epsilon for comparison /// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead. /// // let error_margin = std::f64::EPSILON; diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 8dba60f3a58..321db08dfe8 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -22,9 +22,12 @@ declare_clippy_lint! { /// ### Example /// ```rust,ignore /// debug_assert_eq!(vec![3].pop(), Some(3)); + /// /// // or - /// fn take_a_mut_parameter(_: &mut u32) -> bool { unimplemented!() } - /// debug_assert!(take_a_mut_parameter(&mut 5)); + /// + /// # let mut x = 5; + /// # fn takes_a_mut_parameter(_: &mut u32) -> bool { unimplemented!() } + /// debug_assert!(takes_a_mut_parameter(&mut x)); /// ``` #[clippy::version = "1.40.0"] pub DEBUG_ASSERT_WITH_MUT_CALL, diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 6c60fb4b8e0..b91be0eb4be 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -54,14 +54,14 @@ declare_clippy_lint! { /// fn func(arg: T) where T: Clone + Default {} /// ``` /// - /// Could be written as: - /// + /// Use instead: /// ```rust + /// # mod hidden { /// fn func(arg: T) {} - /// ``` - /// or + /// # } + /// + /// // or /// - /// ```rust /// fn func(arg: T) where T: Clone + Default {} /// ``` #[clippy::version = "1.47.0"] -- cgit 1.4.1-3-g733a5 From e67b2bf732876eeb26e0d2fbc4b6c55e1a9f9317 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 23 Sep 2022 13:42:59 -0400 Subject: Apply uninlined_format-args to clippy_lints This change is needed for the uninlined_format-args lint to be merged. See https://github.com/rust-lang/rust-clippy/pull/9233 --- clippy_lints/src/approx_const.rs | 4 +-- clippy_lints/src/asm_syntax.rs | 2 +- clippy_lints/src/assertions_on_constants.rs | 4 +-- clippy_lints/src/assertions_on_result_states.rs | 10 +++--- clippy_lints/src/attrs.rs | 7 ++-- clippy_lints/src/bool_assert_comparison.rs | 4 +-- clippy_lints/src/booleans.rs | 5 ++- clippy_lints/src/cargo/common_metadata.rs | 2 +- clippy_lints/src/cargo/feature_name.rs | 4 +-- clippy_lints/src/cargo/mod.rs | 4 +-- clippy_lints/src/cargo/multiple_crate_versions.rs | 2 +- clippy_lints/src/casts/borrow_as_ptr.rs | 2 +- clippy_lints/src/casts/cast_lossless.rs | 12 ++----- clippy_lints/src/casts/cast_possible_truncation.rs | 16 +++------ clippy_lints/src/casts/cast_possible_wrap.rs | 5 +-- clippy_lints/src/casts/cast_ptr_alignment.rs | 4 +-- clippy_lints/src/casts/cast_sign_loss.rs | 5 +-- .../src/casts/cast_slice_different_sizes.rs | 4 +-- clippy_lints/src/casts/char_lit_as_u8.rs | 2 +- clippy_lints/src/casts/fn_to_numeric_cast.rs | 4 +-- clippy_lints/src/casts/fn_to_numeric_cast_any.rs | 4 +-- .../casts/fn_to_numeric_cast_with_truncation.rs | 7 ++-- clippy_lints/src/casts/ptr_as_ptr.rs | 4 +-- clippy_lints/src/casts/unnecessary_cast.rs | 9 ++--- clippy_lints/src/checked_conversions.rs | 2 +- clippy_lints/src/cognitive_complexity.rs | 3 +- clippy_lints/src/default.rs | 17 ++++----- clippy_lints/src/default_numeric_fallback.rs | 4 +-- clippy_lints/src/dereference.rs | 14 ++++---- clippy_lints/src/disallowed_methods.rs | 2 +- clippy_lints/src/disallowed_script_idents.rs | 3 +- clippy_lints/src/disallowed_types.rs | 4 +-- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/entry.rs | 28 ++++----------- clippy_lints/src/enum_variants.rs | 7 ++-- clippy_lints/src/equatable_if_let.rs | 3 +- clippy_lints/src/eta_reduction.rs | 4 +-- clippy_lints/src/exhaustive_items.rs | 2 +- clippy_lints/src/explicit_write.rs | 8 ++--- clippy_lints/src/float_literal.rs | 6 ++-- clippy_lints/src/floating_point_arithmetic.rs | 7 ++-- clippy_lints/src/format.rs | 2 +- clippy_lints/src/format_args.rs | 17 ++++----- clippy_lints/src/format_impl.rs | 6 ++-- clippy_lints/src/formatting.rs | 25 +++++--------- clippy_lints/src/from_str_radix_10.rs | 2 +- clippy_lints/src/functions/must_use.rs | 2 +- clippy_lints/src/functions/too_many_arguments.rs | 5 +-- clippy_lints/src/functions/too_many_lines.rs | 5 +-- clippy_lints/src/if_then_some_else_none.rs | 9 +++-- clippy_lints/src/implicit_hasher.rs | 7 ++-- clippy_lints/src/implicit_return.rs | 4 +-- clippy_lints/src/implicit_saturating_sub.rs | 2 +- .../src/inconsistent_struct_constructor.rs | 6 ++-- clippy_lints/src/index_refutable_slice.rs | 4 +-- clippy_lints/src/inherent_to_string.rs | 12 +++---- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/int_plus_one.rs | 4 +-- clippy_lints/src/iter_not_returning_iterator.rs | 5 +-- clippy_lints/src/len_zero.rs | 35 ++++++++----------- clippy_lints/src/let_if_seq.rs | 3 +- clippy_lints/src/lib.rs | 11 +++--- clippy_lints/src/literal_representation.rs | 2 +- clippy_lints/src/loops/explicit_counter_loop.rs | 14 +++----- clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_lints/src/loops/for_kv_map.rs | 4 +-- clippy_lints/src/loops/manual_flatten.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 13 ++----- clippy_lints/src/loops/needless_collect.rs | 6 ++-- clippy_lints/src/loops/needless_range_loop.rs | 10 +++--- clippy_lints/src/loops/never_loop.rs | 6 +--- clippy_lints/src/loops/same_item_push.rs | 5 +-- clippy_lints/src/loops/utils.rs | 3 +- clippy_lints/src/loops/while_let_on_iterator.rs | 2 +- clippy_lints/src/macro_use.rs | 6 ++-- clippy_lints/src/manual_async_fn.rs | 6 ++-- clippy_lints/src/manual_non_exhaustive.rs | 4 +-- clippy_lints/src/manual_retain.rs | 14 +++----- clippy_lints/src/manual_strip.rs | 9 +++-- clippy_lints/src/map_unit_fn.rs | 5 +-- clippy_lints/src/match_result_ok.rs | 6 ++-- clippy_lints/src/matches/manual_map.rs | 14 ++++---- clippy_lints/src/matches/manual_unwrap_or.rs | 6 ++-- clippy_lints/src/matches/match_as_ref.rs | 6 ++-- clippy_lints/src/matches/match_like_matches.rs | 5 ++- clippy_lints/src/matches/match_same_arms.rs | 2 +- clippy_lints/src/matches/match_single_binding.rs | 28 ++++++--------- .../src/matches/match_str_case_mismatch.rs | 4 +-- clippy_lints/src/matches/match_wild_err_arm.rs | 2 +- .../src/matches/redundant_pattern_match.rs | 8 ++--- .../src/matches/significant_drop_in_scrutinee.rs | 6 ++-- clippy_lints/src/matches/single_match.rs | 6 ++-- clippy_lints/src/matches/try_err.rs | 4 +-- clippy_lints/src/methods/bind_instead_of_map.rs | 2 +- clippy_lints/src/methods/bytes_nth.rs | 2 +- clippy_lints/src/methods/chars_cmp.rs | 5 ++- clippy_lints/src/methods/chars_cmp_with_unwrap.rs | 5 ++- clippy_lints/src/methods/clone_on_copy.rs | 13 ++++--- clippy_lints/src/methods/clone_on_ref_ptr.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 11 +++--- clippy_lints/src/methods/filetype_is_file.rs | 4 +-- clippy_lints/src/methods/filter_map_next.rs | 2 +- clippy_lints/src/methods/filter_next.rs | 2 +- .../src/methods/from_iter_instead_of_collect.rs | 6 ++-- clippy_lints/src/methods/get_first.rs | 4 +-- clippy_lints/src/methods/get_unwrap.rs | 11 ++---- clippy_lints/src/methods/implicit_clone.rs | 6 ++-- clippy_lints/src/methods/inefficient_to_string.rs | 7 ++-- clippy_lints/src/methods/into_iter_on_ref.rs | 3 +- clippy_lints/src/methods/is_digit_ascii_radix.rs | 7 ++-- clippy_lints/src/methods/iter_cloned_collect.rs | 4 +-- clippy_lints/src/methods/iter_count.rs | 2 +- clippy_lints/src/methods/iter_kv_map.rs | 8 ++--- clippy_lints/src/methods/iter_next_slice.rs | 2 +- clippy_lints/src/methods/iter_nth.rs | 4 +-- clippy_lints/src/methods/iter_with_drain.rs | 2 +- clippy_lints/src/methods/manual_ok_or.rs | 4 +-- .../src/methods/manual_saturating_arithmetic.rs | 5 ++- clippy_lints/src/methods/manual_str_repeat.rs | 2 +- clippy_lints/src/methods/map_clone.rs | 5 ++- clippy_lints/src/methods/map_flatten.rs | 9 ++--- clippy_lints/src/methods/map_identity.rs | 2 +- clippy_lints/src/methods/map_unwrap_or.rs | 2 +- clippy_lints/src/methods/option_as_ref_deref.rs | 9 +++-- clippy_lints/src/methods/option_map_or_none.rs | 6 ++-- clippy_lints/src/methods/option_map_unwrap_or.rs | 9 +++-- clippy_lints/src/methods/or_fun_call.rs | 10 +++--- clippy_lints/src/methods/search_is_some.rs | 14 +++----- .../src/methods/single_char_insert_string.rs | 2 +- .../src/methods/single_char_push_string.rs | 2 +- clippy_lints/src/methods/stable_sort_primitive.rs | 4 +-- clippy_lints/src/methods/string_extend_chars.rs | 3 +- clippy_lints/src/methods/suspicious_splitn.rs | 4 +-- clippy_lints/src/methods/suspicious_to_owned.rs | 4 +-- clippy_lints/src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/methods/unnecessary_fold.rs | 7 ++-- .../src/methods/unnecessary_iter_cloned.rs | 2 +- clippy_lints/src/methods/unnecessary_lazy_eval.rs | 4 +-- clippy_lints/src/methods/unnecessary_to_owned.rs | 21 ++++++------ clippy_lints/src/methods/useless_asref.rs | 2 +- clippy_lints/src/methods/wrong_self_convention.rs | 15 ++++---- clippy_lints/src/misc.rs | 18 ++++------ clippy_lints/src/misc_early/literal_suffix.rs | 8 ++--- clippy_lints/src/misc_early/mod.rs | 5 ++- .../src/misc_early/unneeded_field_pattern.rs | 4 +-- clippy_lints/src/mismatching_type_param_order.rs | 7 ++-- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_enforced_import_rename.rs | 4 +-- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/mutable_debug_assertion.rs | 5 +-- clippy_lints/src/mutex_atomic.rs | 5 ++- clippy_lints/src/needless_continue.rs | 14 +++----- clippy_lints/src/needless_late_init.rs | 10 +++--- clippy_lints/src/needless_pass_by_value.rs | 4 +-- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/neg_multiply.rs | 4 +-- clippy_lints/src/new_without_default.rs | 7 ++-- clippy_lints/src/non_expressive_names.rs | 5 +-- clippy_lints/src/nonstandard_macro_braces.rs | 12 +++---- clippy_lints/src/octal_escapes.rs | 2 +- .../src/operators/absurd_extreme_comparisons.rs | 5 ++- clippy_lints/src/operators/assign_op_pattern.rs | 2 +- clippy_lints/src/operators/bit_mask.rs | 40 +++++----------------- clippy_lints/src/operators/cmp_owned.rs | 10 +++--- clippy_lints/src/operators/duration_subsec.rs | 7 ++-- clippy_lints/src/operators/eq_op.rs | 2 +- .../src/operators/misrefactored_assign_op.rs | 12 +++---- .../src/operators/needless_bitwise_bool.rs | 2 +- clippy_lints/src/operators/ptr_eq.rs | 2 +- clippy_lints/src/operators/self_assignment.rs | 2 +- clippy_lints/src/operators/verbose_bit_mask.rs | 2 +- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 4 +-- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/ptr_offset_with_cast.rs | 4 +-- clippy_lints/src/question_mark.rs | 7 ++-- clippy_lints/src/ranges.rs | 16 ++++----- clippy_lints/src/read_zero_byte_vec.rs | 3 +- clippy_lints/src/redundant_pub_crate.rs | 2 +- clippy_lints/src/redundant_slicing.rs | 8 ++--- clippy_lints/src/redundant_static_lifetimes.rs | 2 +- clippy_lints/src/regex.rs | 4 +-- clippy_lints/src/same_name_method.rs | 4 +-- clippy_lints/src/semicolon_if_nothing_returned.rs | 2 +- clippy_lints/src/slow_vector_initialization.rs | 2 +- clippy_lints/src/strings.rs | 6 ++-- clippy_lints/src/strlen_on_c_strings.rs | 2 +- clippy_lints/src/suspicious_operation_groupings.rs | 9 ++--- clippy_lints/src/swap.rs | 19 +++++----- clippy_lints/src/swap_ptr_to_ref.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 4 +-- clippy_lints/src/trait_bounds.rs | 3 +- .../src/transmute/crosspointer_transmute.rs | 10 ++---- .../src/transmute/transmute_float_to_int.rs | 4 +-- .../src/transmute/transmute_int_to_bool.rs | 2 +- .../src/transmute/transmute_int_to_char.rs | 4 +-- .../src/transmute/transmute_int_to_float.rs | 4 +-- .../src/transmute/transmute_num_to_bytes.rs | 4 +-- clippy_lints/src/transmute/transmute_ptr_to_ref.rs | 18 ++++------ clippy_lints/src/transmute/transmute_ref_to_ref.rs | 2 +- .../src/transmute/transmute_undefined_repr.rs | 23 ++++++------- .../transmutes_expressible_as_ptr_casts.rs | 5 +-- .../src/transmute/unsound_collection_transmute.rs | 5 +-- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_lints/src/transmute/wrong_transmute.rs | 2 +- clippy_lints/src/types/borrowed_box.rs | 6 ++-- clippy_lints/src/types/box_collection.rs | 2 +- clippy_lints/src/types/rc_buffer.rs | 4 +-- clippy_lints/src/types/redundant_allocation.rs | 29 +++++----------- clippy_lints/src/unit_return_expecting_ord.rs | 6 ++-- clippy_lints/src/unit_types/unit_arg.rs | 7 ++-- clippy_lints/src/unit_types/unit_cmp.rs | 7 ++-- clippy_lints/src/unnecessary_self_imports.rs | 2 +- clippy_lints/src/unnecessary_wraps.rs | 7 ++-- clippy_lints/src/unsafe_removed_from_name.rs | 5 +-- clippy_lints/src/unused_rounding.rs | 4 +-- clippy_lints/src/unwrap.rs | 7 ++-- clippy_lints/src/upper_case_acronyms.rs | 2 +- clippy_lints/src/useless_conversion.rs | 10 +++--- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/conf.rs | 9 ++--- clippy_lints/src/wildcard_imports.rs | 2 +- clippy_lints/src/zero_div_zero.rs | 3 +- 225 files changed, 557 insertions(+), 842 deletions(-) (limited to 'clippy_lints/src/mutable_debug_assertion.rs') diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 159f3b0cd01..724490fb495 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -92,7 +92,7 @@ impl ApproxConstant { cx, APPROX_CONSTANT, e.span, - &format!("approximate value of `{}::consts::{}` found", module, &name), + &format!("approximate value of `{module}::consts::{}` found", &name), None, "consider using the constant directly", ); @@ -126,7 +126,7 @@ fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool { // The value is a truncated constant true } else { - let round_const = format!("{:.*}", value.len() - 2, constant); + let round_const = format!("{constant:.*}", value.len() - 2); value == round_const } } diff --git a/clippy_lints/src/asm_syntax.rs b/clippy_lints/src/asm_syntax.rs index f419781dbc8..ad31d708f64 100644 --- a/clippy_lints/src/asm_syntax.rs +++ b/clippy_lints/src/asm_syntax.rs @@ -44,7 +44,7 @@ fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr cx, lint, expr.span, - &format!("{} x86 assembly syntax used", style), + &format!("{style} x86 assembly syntax used"), None, &format!("use {} x86 assembly syntax", !style), ); diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 2705ffffdcb..a36df55d0bd 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -60,9 +60,9 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { cx, ASSERTIONS_ON_CONSTANTS, macro_call.span, - &format!("`assert!(false{})` should probably be replaced", assert_arg), + &format!("`assert!(false{assert_arg})` should probably be replaced"), None, - &format!("use `panic!({})` or `unreachable!({0})`", panic_arg), + &format!("use `panic!({panic_arg})` or `unreachable!({panic_arg})`"), ); } } diff --git a/clippy_lints/src/assertions_on_result_states.rs b/clippy_lints/src/assertions_on_result_states.rs index 656dc5feeb5..f6d6c23bb6e 100644 --- a/clippy_lints/src/assertions_on_result_states.rs +++ b/clippy_lints/src/assertions_on_result_states.rs @@ -69,9 +69,8 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates { "called `assert!` with `Result::is_ok`", "replace with", format!( - "{}.unwrap(){}", - snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0, - semicolon + "{}.unwrap(){semicolon}", + snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0 ), app, ); @@ -84,9 +83,8 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates { "called `assert!` with `Result::is_err`", "replace with", format!( - "{}.unwrap_err(){}", - snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0, - semicolon + "{}.unwrap_err(){semicolon}", + snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0 ), app, ); diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 732dc2b4330..5f45c69d7f9 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -541,10 +541,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut cx, INLINE_ALWAYS, attr.span, - &format!( - "you have declared `#[inline(always)]` on `{}`. This is usually a bad idea", - name - ), + &format!("you have declared `#[inline(always)]` on `{name}`. This is usually a bad idea"), ); } } @@ -720,7 +717,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) { let mut unix_suggested = false; for (os, span) in mismatched { - let sugg = format!("target_os = \"{}\"", os); + let sugg = format!("target_os = \"{os}\""); diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect); if !unix_suggested && is_unix(os) { diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index 95abe8aa59f..4bd55c1429c 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -98,9 +98,9 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison { cx, BOOL_ASSERT_COMPARISON, macro_call.span, - &format!("used `{}!` with a literal bool", macro_name), + &format!("used `{macro_name}!` with a literal bool"), "replace it with", - format!("{}!(..)", non_eq_mac), + format!("{non_eq_mac}!(..)"), Applicability::MaybeIncorrect, ); } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 03d262d5a59..2a15cbc7a3c 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -263,9 +263,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { } .and_then(|op| { Some(format!( - "{}{}{}", + "{}{op}{}", snippet_opt(cx, lhs.span)?, - op, snippet_opt(cx, rhs.span)? )) }) @@ -285,7 +284,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let path: &str = path.ident.name.as_str(); a == path }) - .and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, receiver.span)?, neg_method))) + .and_then(|(_, neg_method)| Some(format!("{}.{neg_method}()", snippet_opt(cx, receiver.span)?))) }, _ => None, } diff --git a/clippy_lints/src/cargo/common_metadata.rs b/clippy_lints/src/cargo/common_metadata.rs index e0442dda479..805121bcced 100644 --- a/clippy_lints/src/cargo/common_metadata.rs +++ b/clippy_lints/src/cargo/common_metadata.rs @@ -40,7 +40,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: b } fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) { - let message = format!("package `{}` is missing `{}` metadata", package.name, field); + let message = format!("package `{}` is missing `{field}` metadata", package.name); span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message); } diff --git a/clippy_lints/src/cargo/feature_name.rs b/clippy_lints/src/cargo/feature_name.rs index 79a469a4258..37c169dbd95 100644 --- a/clippy_lints/src/cargo/feature_name.rs +++ b/clippy_lints/src/cargo/feature_name.rs @@ -57,10 +57,8 @@ fn lint(cx: &LateContext<'_>, feature: &str, substring: &str, is_prefix: bool) { }, DUMMY_SP, &format!( - "the \"{}\" {} in the feature name \"{}\" is {}", - substring, + "the \"{substring}\" {} in the feature name \"{feature}\" is {}", if is_prefix { "prefix" } else { "suffix" }, - feature, if is_negative { "negative" } else { "redundant" } ), None, diff --git a/clippy_lints/src/cargo/mod.rs b/clippy_lints/src/cargo/mod.rs index 9f45db86a09..3a872e54c9a 100644 --- a/clippy_lints/src/cargo/mod.rs +++ b/clippy_lints/src/cargo/mod.rs @@ -196,7 +196,7 @@ impl LateLintPass<'_> for Cargo { }, Err(e) => { for lint in NO_DEPS_LINTS { - span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {}", e)); + span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {e}")); } }, } @@ -212,7 +212,7 @@ impl LateLintPass<'_> for Cargo { }, Err(e) => { for lint in WITH_DEPS_LINTS { - span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {}", e)); + span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {e}")); } }, } diff --git a/clippy_lints/src/cargo/multiple_crate_versions.rs b/clippy_lints/src/cargo/multiple_crate_versions.rs index 76fd0819a39..f9b17d45e9f 100644 --- a/clippy_lints/src/cargo/multiple_crate_versions.rs +++ b/clippy_lints/src/cargo/multiple_crate_versions.rs @@ -37,7 +37,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata) { cx, MULTIPLE_CRATE_VERSIONS, DUMMY_SP, - &format!("multiple versions for dependency `{}`: {}", name, versions), + &format!("multiple versions for dependency `{name}`: {versions}"), ); } } diff --git a/clippy_lints/src/casts/borrow_as_ptr.rs b/clippy_lints/src/casts/borrow_as_ptr.rs index 6e1f8cd64f0..294d22d34de 100644 --- a/clippy_lints/src/casts/borrow_as_ptr.rs +++ b/clippy_lints/src/casts/borrow_as_ptr.rs @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>( expr.span, "borrow as raw pointer", "try", - format!("{}::ptr::{}!({})", core_or_std, macro_name, snip), + format!("{core_or_std}::ptr::{macro_name}!({snip})"), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/casts/cast_lossless.rs b/clippy_lints/src/casts/cast_lossless.rs index 938458e30ca..13c403234da 100644 --- a/clippy_lints/src/casts/cast_lossless.rs +++ b/clippy_lints/src/casts/cast_lossless.rs @@ -41,15 +41,9 @@ pub(super) fn check( ); let message = if cast_from.is_bool() { - format!( - "casting `{0:}` to `{1:}` is more cleanly stated with `{1:}::from(_)`", - cast_from, cast_to - ) + format!("casting `{cast_from:}` to `{cast_to:}` is more cleanly stated with `{cast_to:}::from(_)`") } else { - format!( - "casting `{}` to `{}` may become silently lossy if you later change the type", - cast_from, cast_to - ) + format!("casting `{cast_from}` to `{cast_to}` may become silently lossy if you later change the type") }; span_lint_and_sugg( @@ -58,7 +52,7 @@ pub(super) fn check( expr.span, &message, "try", - format!("{}::from({})", cast_to, sugg), + format!("{cast_to}::from({sugg})"), applicability, ); } diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 406547a4454..88deb4565eb 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -103,10 +103,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, return; } - format!( - "casting `{}` to `{}` may truncate the value{}", - cast_from, cast_to, suffix, - ) + format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",) }, (ty::Adt(def, _), true) if def.is_enum() => { @@ -142,20 +139,17 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, CAST_ENUM_TRUNCATION, expr.span, &format!( - "casting `{}::{}` to `{}` will truncate the value{}", - cast_from, variant.name, cast_to, suffix, + "casting `{cast_from}::{}` to `{cast_to}` will truncate the value{suffix}", + variant.name, ), ); return; } - format!( - "casting `{}` to `{}` may truncate the value{}", - cast_from, cast_to, suffix, - ) + format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",) }, (ty::Float(_), true) => { - format!("casting `{}` to `{}` may truncate the value", cast_from, cast_to) + format!("casting `{cast_from}` to `{cast_to}` may truncate the value") }, (ty::Float(FloatTy::F64), false) if matches!(cast_to.kind(), &ty::Float(FloatTy::F32)) => { diff --git a/clippy_lints/src/casts/cast_possible_wrap.rs b/clippy_lints/src/casts/cast_possible_wrap.rs index 2c5c1d7cb46..28ecdea7ea0 100644 --- a/clippy_lints/src/casts/cast_possible_wrap.rs +++ b/clippy_lints/src/casts/cast_possible_wrap.rs @@ -35,10 +35,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca cx, CAST_POSSIBLE_WRAP, expr.span, - &format!( - "casting `{}` to `{}` may wrap around the value{}", - cast_from, cast_to, suffix, - ), + &format!("casting `{cast_from}` to `{cast_to}` may wrap around the value{suffix}",), ); } } diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index da7b12f6726..97054a0d101 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -49,9 +49,7 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_f CAST_PTR_ALIGNMENT, expr.span, &format!( - "casting from `{}` to a more-strictly-aligned pointer (`{}`) ({} < {} bytes)", - cast_from, - cast_to, + "casting from `{cast_from}` to a more-strictly-aligned pointer (`{cast_to}`) ({} < {} bytes)", from_layout.align.abi.bytes(), to_layout.align.abi.bytes(), ), diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs index 5b59350be04..a20a97d4e56 100644 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ b/clippy_lints/src/casts/cast_sign_loss.rs @@ -14,10 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_op: &Expr<'_>, c cx, CAST_SIGN_LOSS, expr.span, - &format!( - "casting `{}` to `{}` may lose the sign of the value", - cast_from, cast_to - ), + &format!("casting `{cast_from}` to `{cast_to}` may lose the sign of the value"), ); } } diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index 027c660ce3b..d31d10d22b9 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -35,8 +35,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Optio CAST_SLICE_DIFFERENT_SIZES, expr.span, &format!( - "casting between raw pointers to `[{}]` (element size {}) and `[{}]` (element size {}) does not adjust the count", - start_ty.ty, from_size, end_ty.ty, to_size, + "casting between raw pointers to `[{}]` (element size {from_size}) and `[{}]` (element size {to_size}) does not adjust the count", + start_ty.ty, end_ty.ty, ), |diag| { let ptr_snippet = source::snippet(cx, left_cast.span, ".."); diff --git a/clippy_lints/src/casts/char_lit_as_u8.rs b/clippy_lints/src/casts/char_lit_as_u8.rs index 7cc406018db..82e07c98a7e 100644 --- a/clippy_lints/src/casts/char_lit_as_u8.rs +++ b/clippy_lints/src/casts/char_lit_as_u8.rs @@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { diag.span_suggestion( expr.span, "use a byte literal instead", - format!("b{}", snippet), + format!("b{snippet}"), applicability, ); } diff --git a/clippy_lints/src/casts/fn_to_numeric_cast.rs b/clippy_lints/src/casts/fn_to_numeric_cast.rs index 35350d8a25b..a26bfab4e7c 100644 --- a/clippy_lints/src/casts/fn_to_numeric_cast.rs +++ b/clippy_lints/src/casts/fn_to_numeric_cast.rs @@ -25,9 +25,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cx, FN_TO_NUMERIC_CAST, expr.span, - &format!("casting function pointer `{}` to `{}`", from_snippet, cast_to), + &format!("casting function pointer `{from_snippet}` to `{cast_to}`"), "try", - format!("{} as usize", from_snippet), + format!("{from_snippet} as usize"), applicability, ); } diff --git a/clippy_lints/src/casts/fn_to_numeric_cast_any.rs b/clippy_lints/src/casts/fn_to_numeric_cast_any.rs index 03621887a34..75654129408 100644 --- a/clippy_lints/src/casts/fn_to_numeric_cast_any.rs +++ b/clippy_lints/src/casts/fn_to_numeric_cast_any.rs @@ -23,9 +23,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cx, FN_TO_NUMERIC_CAST_ANY, expr.span, - &format!("casting function pointer `{}` to `{}`", from_snippet, cast_to), + &format!("casting function pointer `{from_snippet}` to `{cast_to}`"), "did you mean to invoke the function?", - format!("{}() as {}", from_snippet, cast_to), + format!("{from_snippet}() as {cast_to}"), applicability, ); }, diff --git a/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs b/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs index 6287f479b5b..556be1d1506 100644 --- a/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs +++ b/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs @@ -24,12 +24,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cx, FN_TO_NUMERIC_CAST_WITH_TRUNCATION, expr.span, - &format!( - "casting function pointer `{}` to `{}`, which truncates the value", - from_snippet, cast_to - ), + &format!("casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value"), "try", - format!("{} as usize", from_snippet), + format!("{from_snippet} as usize"), applicability, ); } diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index 46d45d09661..c2b9253ec35 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Option Cow::Borrowed(""), TyKind::Ptr(mut_ty) if matches!(mut_ty.ty.kind, TyKind::Infer) => Cow::Borrowed(""), - _ => Cow::Owned(format!("::<{}>", to_pointee_ty)), + _ => Cow::Owned(format!("::<{to_pointee_ty}>")), }; span_lint_and_sugg( cx, @@ -41,7 +41,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Option( cx, UNNECESSARY_CAST, expr.span, - &format!( - "casting to the same type is unnecessary (`{}` -> `{}`)", - cast_from, cast_to - ), + &format!("casting to the same type is unnecessary (`{cast_from}` -> `{cast_to}`)"), "try", literal_str, Applicability::MachineApplicable, @@ -101,9 +98,9 @@ fn lint_unnecessary_cast(cx: &LateContext<'_>, expr: &Expr<'_>, literal_str: &st cx, UNNECESSARY_CAST, expr.span, - &format!("casting {} literal to `{}` is unnecessary", literal_kind_name, cast_to), + &format!("casting {literal_kind_name} literal to `{cast_to}` is unnecessary"), "try", - format!("{}_{}", matchless.trim_end_matches('.'), cast_to), + format!("{}_{cast_to}", matchless.trim_end_matches('.')), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 37b2fdcff09..1d113c7cbee 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions { item.span, "checked cast can be simplified", "try", - format!("{}::try_from({}).is_ok()", to_type, snippet), + format!("{to_type}::try_from({snippet}).is_ok()"), applicability, ); } diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 33c44f8b2db..fed04ae7f3d 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -107,8 +107,7 @@ impl CognitiveComplexity { COGNITIVE_COMPLEXITY, fn_span, &format!( - "the function has a cognitive complexity of ({}/{})", - rust_cc, + "the function has a cognitive complexity of ({rust_cc}/{})", self.limit.limit() ), None, diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 74f7df61177..cb6800c8ba2 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { cx, DEFAULT_TRAIT_ACCESS, expr.span, - &format!("calling `{}` is more clear than this expression", replacement), + &format!("calling `{replacement}` is more clear than this expression"), "try", replacement, Applicability::Unspecified, // First resolve the TODO above @@ -210,7 +210,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { .map(|(field, rhs)| { // extract and store the assigned value for help message let value_snippet = snippet_with_macro_callsite(cx, rhs.span, ".."); - format!("{}: {}", field, value_snippet) + format!("{field}: {value_snippet}") }) .collect::>() .join(", "); @@ -227,7 +227,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { .map(ToString::to_string) .collect::>() .join(", "); - format!("{}::<{}>", adt_def_ty_name, &tys_str) + format!("{adt_def_ty_name}::<{}>", &tys_str) } else { binding_type.to_string() } @@ -235,12 +235,12 @@ impl<'tcx> LateLintPass<'tcx> for Default { let sugg = if ext_with_default { if field_list.is_empty() { - format!("{}::default()", binding_type) + format!("{binding_type}::default()") } else { - format!("{} {{ {}, ..Default::default() }}", binding_type, field_list) + format!("{binding_type} {{ {field_list}, ..Default::default() }}") } } else { - format!("{} {{ {} }}", binding_type, field_list) + format!("{binding_type} {{ {field_list} }}") }; // span lint once per statement that binds default @@ -250,10 +250,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { first_assign.unwrap().span, "field assignment outside of initializer for an instance created with Default::default()", Some(local.span), - &format!( - "consider initializing the variable with `{}` and removing relevant reassignments", - sugg - ), + &format!("consider initializing the variable with `{sugg}` and removing relevant reassignments"), ); self.reassigned_linted.insert(span); } diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index be02f328e98..3ed9cd36a22 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -95,8 +95,8 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> { src } else { match lit.node { - LitKind::Int(src, _) => format!("{}", src), - LitKind::Float(src, _) => format!("{}", src), + LitKind::Int(src, _) => format!("{src}"), + LitKind::Float(src, _) => format!("{src}"), _ => return, } }; diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index b965d27afce..e272283152d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1308,7 +1308,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data }; let expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence().order() < PREC_PREFIX { - format!("({})", expr_str) + format!("({expr_str})") } else { expr_str.into_owned() }; @@ -1322,7 +1322,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data Mutability::Mut => "explicit `deref_mut` method call", }, "try this", - format!("{}{}{}", addr_of_str, deref_str, expr_str), + format!("{addr_of_str}{deref_str}{expr_str}"), app, ); }, @@ -1336,7 +1336,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data && !has_enclosing_paren(&snip) && (expr.precedence().order() < data.position.precedence() || calls_field) { - format!("({})", snip) + format!("({snip})") } else { snip.into() }; @@ -1379,9 +1379,9 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data let (snip, snip_is_macro) = snippet_with_context(cx, expr.span, data.span.ctxt(), "..", &mut app); let sugg = if !snip_is_macro && expr.precedence().order() < precedence && !has_enclosing_paren(&snip) { - format!("{}({})", prefix, snip) + format!("{prefix}({snip})") } else { - format!("{}{}", prefix, snip) + format!("{prefix}{snip}") }; diag.span_suggestion(data.span, "try this", sugg, app); }, @@ -1460,14 +1460,14 @@ impl Dereferencing { } else { pat.always_deref = false; let snip = snippet_with_context(cx, e.span, parent.span.ctxt(), "..", &mut pat.app).0; - pat.replacements.push((e.span, format!("&{}", snip))); + pat.replacements.push((e.span, format!("&{snip}"))); } }, _ if !e.span.from_expansion() => { // Double reference might be needed at this point. pat.always_deref = false; let snip = snippet_with_applicability(cx, e.span, "..", &mut pat.app); - pat.replacements.push((e.span, format!("&{}", snip))); + pat.replacements.push((e.span, format!("&{snip}"))); }, // Edge case for macros. The span of the identifier will usually match the context of the // binding, but not if the identifier was created in a macro. e.g. `concat_idents` and proc diff --git a/clippy_lints/src/disallowed_methods.rs b/clippy_lints/src/disallowed_methods.rs index 53973ab792a..b02f87c07db 100644 --- a/clippy_lints/src/disallowed_methods.rs +++ b/clippy_lints/src/disallowed_methods.rs @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods { reason: Some(reason), .. } = conf { - diag.note(&format!("{} (from clippy.toml)", reason)); + diag.note(&format!("{reason} (from clippy.toml)")); } }); } diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index 0c27c3f9255..084190f0013 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -99,8 +99,7 @@ impl EarlyLintPass for DisallowedScriptIdents { DISALLOWED_SCRIPT_IDENTS, span, &format!( - "identifier `{}` has a Unicode script that is not allowed by configuration: {}", - symbol_str, + "identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}", script.full_name() ), ); diff --git a/clippy_lints/src/disallowed_types.rs b/clippy_lints/src/disallowed_types.rs index 14f89edce61..53451238d9a 100644 --- a/clippy_lints/src/disallowed_types.rs +++ b/clippy_lints/src/disallowed_types.rs @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes { conf::DisallowedType::Simple(path) => (path, None), conf::DisallowedType::WithReason { path, reason } => ( path, - reason.as_ref().map(|reason| format!("{} (from clippy.toml)", reason)), + reason.as_ref().map(|reason| format!("{reason} (from clippy.toml)")), ), }; let segs: Vec<_> = path.split("::").collect(); @@ -130,7 +130,7 @@ fn emit(cx: &LateContext<'_>, name: &str, span: Span, reason: Option<&str>) { cx, DISALLOWED_TYPES, span, - &format!("`{}` is not allowed according to config", name), + &format!("`{name}` is not allowed according to config"), |diag| { if let Some(reason) = reason { diag.note(reason); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index eb158d850fa..fa50a2d1a2c 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -790,7 +790,7 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) { diag.span_suggestion_with_style( span, "try", - format!("`{}`", snippet), + format!("`{snippet}`"), applicability, // always show the suggestion in a separate line, since the // inline presentation adds another pair of backticks diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index b35f0b8ca52..0ee07fbcc75 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -236,7 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { expr.span, msg, Some(arg.span), - &format!("argument has type `{}`", arg_ty), + &format!("argument has type `{arg_ty}`"), ); } } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index e70df3f53c7..9c834cf0144 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -113,13 +113,8 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass { ), }; format!( - "if let {}::{} = {}.entry({}) {} else {}", + "if let {}::{entry_kind} = {map_str}.entry({key_str}) {then_str} else {else_str}", map_ty.entry_path(), - entry_kind, - map_str, - key_str, - then_str, - else_str, ) } else { // if .. { insert } else { insert } @@ -137,16 +132,11 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass { let indent_str = snippet_indent(cx, expr.span); let indent_str = indent_str.as_deref().unwrap_or(""); format!( - "match {}.entry({}) {{\n{indent} {entry}::{} => {}\n\ - {indent} {entry}::{} => {}\n{indent}}}", - map_str, - key_str, - then_entry, + "match {map_str}.entry({key_str}) {{\n{indent_str} {entry}::{then_entry} => {}\n\ + {indent_str} {entry}::{else_entry} => {}\n{indent_str}}}", reindent_multiline(then_str.into(), true, Some(4 + indent_str.len())), - else_entry, reindent_multiline(else_str.into(), true, Some(4 + indent_str.len())), entry = map_ty.entry_path(), - indent = indent_str, ) } } else { @@ -163,20 +153,16 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass { then_search.snippet_occupied(cx, then_expr.span, &mut app) }; format!( - "if let {}::{} = {}.entry({}) {}", + "if let {}::{entry_kind} = {map_str}.entry({key_str}) {body_str}", map_ty.entry_path(), - entry_kind, - map_str, - key_str, - body_str, ) } else if let Some(insertion) = then_search.as_single_insertion() { let value_str = snippet_with_context(cx, insertion.value.span, then_expr.span.ctxt(), "..", &mut app).0; if contains_expr.negated { if insertion.value.can_have_side_effects() { - format!("{}.entry({}).or_insert_with(|| {});", map_str, key_str, value_str) + format!("{map_str}.entry({key_str}).or_insert_with(|| {value_str});") } else { - format!("{}.entry({}).or_insert({});", map_str, key_str, value_str) + format!("{map_str}.entry({key_str}).or_insert({value_str});") } } else { // TODO: suggest using `if let Some(v) = map.get_mut(k) { .. }` here. @@ -186,7 +172,7 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass { } else { let block_str = then_search.snippet_closure(cx, then_expr.span, &mut app); if contains_expr.negated { - format!("{}.entry({}).or_insert_with(|| {});", map_str, key_str, block_str) + format!("{map_str}.entry({key_str}).or_insert_with(|| {block_str});") } else { // TODO: suggest using `if let Some(v) = map.get_mut(k) { .. }` here. // This would need to be a different lint. diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index cd36f9fcd72..d8c6b4e39ae 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -202,12 +202,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n cx, ENUM_VARIANT_NAMES, span, - &format!("all variants have the same {}fix: `{}`", what, value), + &format!("all variants have the same {what}fix: `{value}`"), None, &format!( - "remove the {}fixes and use full paths to \ - the variants instead of glob imports", - what + "remove the {what}fixes and use full paths to \ + the variants instead of glob imports" ), ); } diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index fdfb821ac78..7917d83c0b9 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -91,9 +91,8 @@ impl<'tcx> LateLintPass<'tcx> for PatternEquality { "this pattern matching can be expressed using equality", "try", format!( - "{} == {}", + "{} == {pat_str}", snippet_with_context(cx, let_expr.init.span, expr.span.ctxt(), "..", &mut applicability).0, - pat_str, ), applicability, ); diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 53bc617a4f5..0f9f94a6b54 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { then { // Mutable closure is used after current expr; we cannot consume it. - snippet = format!("&mut {}", snippet); + snippet = format!("&mut {snippet}"); } } diag.span_suggestion( @@ -158,7 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { diag.span_suggestion( expr.span, "replace the closure with the method itself", - format!("{}::{}", name, path.ident.name), + format!("{name}::{}", path.ident.name), Applicability::MachineApplicable, ); }) diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index 173d41b4b05..218e40f2b5f 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -97,7 +97,7 @@ impl LateLintPass<'_> for ExhaustiveItems { item.span, msg, |diag| { - let sugg = format!("#[non_exhaustive]\n{}", indent); + let sugg = format!("#[non_exhaustive]\n{indent}"); diag.span_suggestion(suggestion_span, "try adding #[non_exhaustive]", sugg, diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index b9ed4af0219..c0ea6f338a2 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -80,12 +80,12 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { // used. let (used, sugg_mac) = if let Some(macro_name) = calling_macro { ( - format!("{}!({}(), ...)", macro_name, dest_name), + format!("{macro_name}!({dest_name}(), ...)"), macro_name.replace("write", "print"), ) } else { ( - format!("{}().write_fmt(...)", dest_name), + format!("{dest_name}().write_fmt(...)"), "print".into(), ) }; @@ -100,9 +100,9 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { cx, EXPLICIT_WRITE, expr.span, - &format!("use of `{}.unwrap()`", used), + &format!("use of `{used}.unwrap()`"), "try this", - format!("{}{}!({})", prefix, sugg_mac, inputs_snippet), + format!("{prefix}{sugg_mac}!({inputs_snippet})"), applicability, ) } diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index f2e07980963..6fee7fb308c 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -173,9 +173,9 @@ impl FloatFormat { T: fmt::UpperExp + fmt::LowerExp + fmt::Display, { match self { - Self::LowerExp => format!("{:e}", f), - Self::UpperExp => format!("{:E}", f), - Self::Normal => format!("{}", f), + Self::LowerExp => format!("{f:e}"), + Self::UpperExp => format!("{f:E}"), + Self::Normal => format!("{f}"), } } } diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index ba53a967880..e71afec12a7 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -142,8 +142,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Su if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node; then { let op = format!( - "{}{}{}", - suggestion, + "{suggestion}{}{}", // Check for float literals without numbers following the decimal // separator such as `2.` and adds a trailing zero if sym.as_str().ends_with('.') { @@ -172,7 +171,7 @@ fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, ar expr.span, "logarithm for bases 2, 10 and e can be computed more accurately", "consider using", - format!("{}.{}()", Sugg::hir(cx, receiver, "..").maybe_par(), method), + format!("{}.{method}()", Sugg::hir(cx, receiver, "..").maybe_par()), Applicability::MachineApplicable, ); } @@ -251,7 +250,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: expr.span, "exponent for bases 2 and e can be computed more accurately", "consider using", - format!("{}.{}()", prepare_receiver_sugg(cx, &args[0]), method), + format!("{}.{method}()", prepare_receiver_sugg(cx, &args[0])), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index f10d8256953..bc0c68f535a 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat { [_] => { // Simulate macro expansion, converting {{ and }} to { and }. let s_expand = format_args.format_string.snippet.replace("{{", "{").replace("}}", "}"); - let sugg = format!("{}.to_string()", s_expand); + let sugg = format!("{s_expand}.to_string()"); span_useless_format(cx, call_site, sugg, applicability); }, [..] => {}, diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index e1c46fd0bfd..192f6258aa5 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -112,11 +112,10 @@ fn check_format_in_format_args(cx: &LateContext<'_>, call_site: Span, name: Symb cx, FORMAT_IN_FORMAT_ARGS, call_site, - &format!("`format!` in `{}!` args", name), + &format!("`format!` in `{name}!` args"), |diag| { diag.help(&format!( - "combine the `format!(..)` arguments with the outer `{}!(..)` call", - name + "combine the `format!(..)` arguments with the outer `{name}!(..)` call" )); diag.help("or consider changing `format!` to `format_args!`"); }, @@ -144,8 +143,7 @@ fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Ex TO_STRING_IN_FORMAT_ARGS, value.span.with_lo(receiver.span.hi()), &format!( - "`to_string` applied to a type that implements `Display` in `{}!` args", - name + "`to_string` applied to a type that implements `Display` in `{name}!` args" ), "remove this", String::new(), @@ -157,16 +155,13 @@ fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Ex TO_STRING_IN_FORMAT_ARGS, value.span, &format!( - "`to_string` applied to a type that implements `Display` in `{}!` args", - name + "`to_string` applied to a type that implements `Display` in `{name}!` args" ), "use this", format!( - "{}{:*>width$}{}", + "{}{:*>n_needed_derefs$}{receiver_snippet}", if needs_ref { "&" } else { "" }, - "", - receiver_snippet, - width = n_needed_derefs + "" ), Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/format_impl.rs b/clippy_lints/src/format_impl.rs index b628fd9f758..ed1342a5465 100644 --- a/clippy_lints/src/format_impl.rs +++ b/clippy_lints/src/format_impl.rs @@ -214,12 +214,12 @@ fn check_print_in_format_impl(cx: &LateContext<'_>, expr: &Expr<'_>, impl_trait: cx, PRINT_IN_FORMAT_IMPL, macro_call.span, - &format!("use of `{}!` in `{}` impl", name, impl_trait.name), + &format!("use of `{name}!` in `{}` impl", impl_trait.name), "replace with", if let Some(formatter_name) = impl_trait.formatter_name { - format!("{}!({}, ..)", replacement, formatter_name) + format!("{replacement}!({formatter_name}, ..)") } else { - format!("{}!(..)", replacement) + format!("{replacement}!(..)") }, Applicability::HasPlaceholders, ); diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 01cefe4af85..a866a68987d 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -154,11 +154,10 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) { eqop_span, &format!( "this looks like you are trying to use `.. {op}= ..`, but you \ - really are doing `.. = ({op} ..)`", - op = op + really are doing `.. = ({op} ..)`" ), None, - &format!("to remove this lint, use either `{op}=` or `= {op}`", op = op), + &format!("to remove this lint, use either `{op}=` or `= {op}`"), ); } } @@ -191,16 +190,12 @@ fn check_unop(cx: &EarlyContext<'_>, expr: &Expr) { SUSPICIOUS_UNARY_OP_FORMATTING, eqop_span, &format!( - "by not having a space between `{binop}` and `{unop}` it looks like \ - `{binop}{unop}` is a single operator", - binop = binop_str, - unop = unop_str + "by not having a space between `{binop_str}` and `{unop_str}` it looks like \ + `{binop_str}{unop_str}` is a single operator" ), None, &format!( - "put a space between `{binop}` and `{unop}` and remove the space after `{unop}`", - binop = binop_str, - unop = unop_str + "put a space between `{binop_str}` and `{unop_str}` and remove the space after `{unop_str}`" ), ); } @@ -246,12 +241,11 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) { cx, SUSPICIOUS_ELSE_FORMATTING, else_span, - &format!("this is an `else {}` but the formatting might hide it", else_desc), + &format!("this is an `else {else_desc}` but the formatting might hide it"), None, &format!( "to remove this lint, remove the `else` or remove the new line between \ - `else` and `{}`", - else_desc, + `else` and `{else_desc}`", ), ); } @@ -320,11 +314,10 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) { cx, SUSPICIOUS_ELSE_FORMATTING, else_span, - &format!("this looks like {} but the `else` is missing", looks_like), + &format!("this looks like {looks_like} but the `else` is missing"), None, &format!( - "to remove this lint, add the missing `else` or add a new line before {}", - next_thing, + "to remove this lint, add the missing `else` or add a new line before {next_thing}", ), ); } diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index 74941d817be..2a82473be8c 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for FromStrRadix10 { exp.span, "this call to `from_str_radix` can be replaced with a call to `str::parse`", "try", - format!("{}.parse::<{}>()", sugg, prim_ty.name_str()), + format!("{sugg}.parse::<{}>()", prim_ty.name_str()), Applicability::MaybeIncorrect ); } diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 00a4937763e..09b97bacd65 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -143,7 +143,7 @@ fn check_must_use_candidate<'tcx>( diag.span_suggestion( fn_span, "add the attribute", - format!("#[must_use] {}", snippet), + format!("#[must_use] {snippet}"), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/functions/too_many_arguments.rs b/clippy_lints/src/functions/too_many_arguments.rs index 5c8d8b8e755..1e08922a616 100644 --- a/clippy_lints/src/functions/too_many_arguments.rs +++ b/clippy_lints/src/functions/too_many_arguments.rs @@ -59,10 +59,7 @@ fn check_arg_number(cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, fn_span: Span, cx, TOO_MANY_ARGUMENTS, fn_span, - &format!( - "this function has too many arguments ({}/{})", - args, too_many_arguments_threshold - ), + &format!("this function has too many arguments ({args}/{too_many_arguments_threshold})"), ); } } diff --git a/clippy_lints/src/functions/too_many_lines.rs b/clippy_lints/src/functions/too_many_lines.rs index 54bdea7ea25..f83f8b40f94 100644 --- a/clippy_lints/src/functions/too_many_lines.rs +++ b/clippy_lints/src/functions/too_many_lines.rs @@ -78,10 +78,7 @@ pub(super) fn check_fn( cx, TOO_MANY_LINES, span, - &format!( - "this function has too many lines ({}/{})", - line_count, too_many_lines_threshold - ), + &format!("this function has too many lines ({line_count}/{too_many_lines_threshold})"), ); } } diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index 11c43247868..0800e0644f7 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { { let cond_snip = snippet_with_macro_callsite(cx, cond.span, "[condition]"); let cond_snip = if matches!(cond.kind, ExprKind::Unary(_, _) | ExprKind::Binary(_, _, _)) { - format!("({})", cond_snip) + format!("({cond_snip})") } else { cond_snip.into_owned() }; @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { let mut method_body = if then_block.stmts.is_empty() { arg_snip.into_owned() } else { - format!("{{ /* snippet */ {} }}", arg_snip) + format!("{{ /* snippet */ {arg_snip} }}") }; let method_name = if switch_to_eager_eval(cx, expr) && meets_msrv(self.msrv, msrvs::BOOL_THEN_SOME) { "then_some" @@ -102,14 +102,13 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { }; let help = format!( - "consider using `bool::{}` like: `{}.{}({})`", - method_name, cond_snip, method_name, method_body, + "consider using `bool::{method_name}` like: `{cond_snip}.{method_name}({method_body})`", ); span_lint_and_help( cx, IF_THEN_SOME_ELSE_NONE, expr.span, - &format!("this could be simplified with `bool::{}`", method_name), + &format!("this could be simplified with `bool::{method_name}`"), None, &help, ); diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 4f9680f60fe..067af79152f 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -89,8 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { ( generics_suggestion_span, format!( - "<{}{}S: ::std::hash::BuildHasher{}>", - generics_snip, + "<{generics_snip}{}S: ::std::hash::BuildHasher{}>", if generics_snip.is_empty() { "" } else { ", " }, if vis.suggestions.is_empty() { "" @@ -263,8 +262,8 @@ impl<'tcx> ImplicitHasherType<'tcx> { fn type_arguments(&self) -> String { match *self { - ImplicitHasherType::HashMap(.., ref k, ref v) => format!("{}, {}", k, v), - ImplicitHasherType::HashSet(.., ref t) => format!("{}", t), + ImplicitHasherType::HashMap(.., ref k, ref v) => format!("{k}, {v}"), + ImplicitHasherType::HashSet(.., ref t) => format!("{t}"), } } diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index feec8ec2e23..cfc988da233 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -53,7 +53,7 @@ fn lint_return(cx: &LateContext<'_>, emission_place: HirId, span: Span) { span, "missing `return` statement", |diag| { - diag.span_suggestion(span, "add `return` as shown", format!("return {}", snip), app); + diag.span_suggestion(span, "add `return` as shown", format!("return {snip}"), app); }, ); } @@ -71,7 +71,7 @@ fn lint_break(cx: &LateContext<'_>, emission_place: HirId, break_span: Span, exp diag.span_suggestion( break_span, "change `break` to `return` as shown", - format!("return {}", snip), + format!("return {snip}"), app, ); }, diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 46654bc61e0..f0dbe17d83a 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -170,7 +170,7 @@ fn print_lint_and_sugg(cx: &LateContext<'_>, var_name: &str, expr: &Expr<'_>) { expr.span, "implicitly performing saturating subtraction", "try", - format!("{} = {}.saturating_sub({});", var_name, var_name, '1'), + format!("{var_name} = {var_name}.saturating_sub({});", '1'), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 14b22d2b50d..e2f2d3d42e6 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor { let mut fields_snippet = String::new(); let (last_ident, idents) = ordered_fields.split_last().unwrap(); for ident in idents { - let _ = write!(fields_snippet, "{}, ", ident); + let _ = write!(fields_snippet, "{ident}, "); } fields_snippet.push_str(&last_ident.to_string()); @@ -100,10 +100,8 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor { String::new() }; - let sugg = format!("{} {{ {}{} }}", + let sugg = format!("{} {{ {fields_snippet}{base_snippet} }}", snippet(cx, qpath.span(), ".."), - fields_snippet, - base_snippet, ); span_lint_and_sugg( diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 0dd7f5bf000..c7b5badaae5 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -139,14 +139,14 @@ fn lint_slice(cx: &LateContext<'_>, slice: &SliceLintInformation) { .map(|(index, _)| *index) .collect::>(); - let value_name = |index| format!("{}_{}", slice.ident.name, index); + let value_name = |index| format!("{}_{index}", slice.ident.name); if let Some(max_index) = used_indices.iter().max() { let opt_ref = if slice.needs_ref { "ref " } else { "" }; let pat_sugg_idents = (0..=*max_index) .map(|index| { if used_indices.contains(&index) { - format!("{}{}", opt_ref, value_name(index)) + format!("{opt_ref}{}", value_name(index)) } else { "_".to_string() } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 17d867aacb5..f171ae2649d 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -131,23 +131,19 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { INHERENT_TO_STRING_SHADOW_DISPLAY, item.span, &format!( - "type `{}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`", - self_type + "type `{self_type}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`" ), None, - &format!("remove the inherent method from type `{}`", self_type), + &format!("remove the inherent method from type `{self_type}`"), ); } else { span_lint_and_help( cx, INHERENT_TO_STRING, item.span, - &format!( - "implementation of inherent method `to_string(&self) -> String` for type `{}`", - self_type - ), + &format!("implementation of inherent method `to_string(&self) -> String` for type `{self_type}`"), None, - &format!("implement trait `Display` for type `{}` instead", self_type), + &format!("implement trait `Display` for type `{self_type}` instead"), ); } } diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index dd7177e0131..d609a5ca4d4 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -51,7 +51,7 @@ fn check_attrs(cx: &LateContext<'_>, name: Symbol, attrs: &[Attribute]) { cx, INLINE_FN_WITHOUT_BODY, attr.span, - &format!("use of `#[inline]` on trait method `{}` which has no body", name), + &format!("use of `#[inline]` on trait method `{name}` which has no body"), |diag| { diag.suggest_remove_item(cx, attr.span, "remove", Applicability::MachineApplicable); }, diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 9a944def3eb..33491da3fc5 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -138,8 +138,8 @@ impl IntPlusOne { if let Some(snippet) = snippet_opt(cx, node.span) { if let Some(other_side_snippet) = snippet_opt(cx, other_side.span) { let rec = match side { - Side::Lhs => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)), - Side::Rhs => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)), + Side::Lhs => Some(format!("{snippet} {binop_string} {other_side_snippet}")), + Side::Rhs => Some(format!("{other_side_snippet} {binop_string} {snippet}")), }; return rec; } diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index b56d87c5348..78815ea5a0a 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -80,10 +80,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI cx, ITER_NOT_RETURNING_ITERATOR, sig.span, - &format!( - "this method is named `{}` but its return type does not implement `Iterator`", - name - ), + &format!("this method is named `{name}` but its return type does not implement `Iterator`"), ); } } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 7ae8ef830fa..e94292b9fac 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -278,15 +278,13 @@ impl<'tcx> LenOutput<'tcx> { _ => "", }; match self { - Self::Integral => format!("expected signature: `({}self) -> bool`", self_ref), - Self::Option(_) => format!( - "expected signature: `({}self) -> bool` or `({}self) -> Option", - self_ref, self_ref - ), - Self::Result(..) => format!( - "expected signature: `({}self) -> bool` or `({}self) -> Result", - self_ref, self_ref - ), + Self::Integral => format!("expected signature: `({self_ref}self) -> bool`"), + Self::Option(_) => { + format!("expected signature: `({self_ref}self) -> bool` or `({self_ref}self) -> Option") + }, + Self::Result(..) => { + format!("expected signature: `({self_ref}self) -> bool` or `({self_ref}self) -> Result") + }, } } } @@ -326,8 +324,7 @@ fn check_for_is_empty<'tcx>( let (msg, is_empty_span, self_kind) = match is_empty { None => ( format!( - "{} `{}` has a public `len` method, but no `is_empty` method", - item_kind, + "{item_kind} `{}` has a public `len` method, but no `is_empty` method", item_name.as_str(), ), None, @@ -335,8 +332,7 @@ fn check_for_is_empty<'tcx>( ), Some(is_empty) if !cx.access_levels.is_exported(is_empty.def_id.expect_local()) => ( format!( - "{} `{}` has a public `len` method, but a private `is_empty` method", - item_kind, + "{item_kind} `{}` has a public `len` method, but a private `is_empty` method", item_name.as_str(), ), Some(cx.tcx.def_span(is_empty.def_id)), @@ -348,8 +344,7 @@ fn check_for_is_empty<'tcx>( { ( format!( - "{} `{}` has a public `len` method, but the `is_empty` method has an unexpected signature", - item_kind, + "{item_kind} `{}` has a public `len` method, but the `is_empty` method has an unexpected signature", item_name.as_str(), ), Some(cx.tcx.def_span(is_empty.def_id)), @@ -419,10 +414,9 @@ fn check_len( LEN_ZERO, span, &format!("length comparison to {}", if compare_to == 0 { "zero" } else { "one" }), - &format!("using `{}is_empty` is clearer and more explicit", op), + &format!("using `{op}is_empty` is clearer and more explicit"), format!( - "{}{}.is_empty()", - op, + "{op}{}.is_empty()", snippet_with_applicability(cx, receiver.span, "_", &mut applicability) ), applicability, @@ -439,10 +433,9 @@ fn check_empty_expr(cx: &LateContext<'_>, span: Span, lit1: &Expr<'_>, lit2: &Ex COMPARISON_TO_EMPTY, span, "comparison to empty slice", - &format!("using `{}is_empty` is clearer and more explicit", op), + &format!("using `{op}is_empty` is clearer and more explicit"), format!( - "{}{}.is_empty()", - op, + "{op}{}.is_empty()", snippet_with_applicability(cx, lit1.span, "_", &mut applicability) ), applicability, diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 10fc0f4018e..13071d64441 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -106,8 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { // use mutably after the `if` let sug = format!( - "let {mut}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};", - mut=mutability, + "let {mutability}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};", name=ident.name, cond=snippet(cx, cond.span, "_"), then=if then.stmts.len() > 1 { " ..;" } else { "" }, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 83fdc15c9f0..8a2a1682eca 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -417,8 +417,7 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se let msrv = conf.msrv.as_ref().and_then(|s| { parse_msrv(s, None, None).or_else(|| { sess.err(&format!( - "error reading Clippy's configuration file. `{}` is not a valid Rust version", - s + "error reading Clippy's configuration file. `{s}` is not a valid Rust version" )); None }) @@ -434,8 +433,7 @@ fn read_msrv(conf: &Conf, sess: &Session) -> Option { let clippy_msrv = conf.msrv.as_ref().and_then(|s| { parse_msrv(s, None, None).or_else(|| { sess.err(&format!( - "error reading Clippy's configuration file. `{}` is not a valid Rust version", - s + "error reading Clippy's configuration file. `{s}` is not a valid Rust version" )); None }) @@ -446,8 +444,7 @@ fn read_msrv(conf: &Conf, sess: &Session) -> Option { // if both files have an msrv, let's compare them and emit a warning if they differ if clippy_msrv != cargo_msrv { sess.warn(&format!( - "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{}` from `clippy.toml`", - clippy_msrv + "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`" )); } @@ -466,7 +463,7 @@ pub fn read_conf(sess: &Session) -> Conf { Ok(Some(path)) => path, Ok(None) => return Conf::default(), Err(error) => { - sess.struct_err(&format!("error finding Clippy's configuration file: {}", error)) + sess.struct_err(&format!("error finding Clippy's configuration file: {error}")) .emit(); return Conf::default(); }, diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index fb2104861c8..25f19b9c6e6 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -478,7 +478,7 @@ impl DecimalLiteralRepresentation { if num_lit.radix == Radix::Decimal; if val >= u128::from(self.threshold); then { - let hex = format!("{:#X}", val); + let hex = format!("{val:#X}"); let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false); let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| { warning_type.display(num_lit.format(), cx, lit.span); diff --git a/clippy_lints/src/loops/explicit_counter_loop.rs b/clippy_lints/src/loops/explicit_counter_loop.rs index 8e3ab26a947..14f22348132 100644 --- a/clippy_lints/src/loops/explicit_counter_loop.rs +++ b/clippy_lints/src/loops/explicit_counter_loop.rs @@ -44,11 +44,10 @@ pub(super) fn check<'tcx>( cx, EXPLICIT_COUNTER_LOOP, span, - &format!("the variable `{}` is used as a loop counter", name), + &format!("the variable `{name}` is used as a loop counter"), "consider using", format!( - "for ({}, {}) in {}.enumerate()", - name, + "for ({name}, {}) in {}.enumerate()", snippet_with_applicability(cx, pat.span, "item", &mut applicability), make_iterator_snippet(cx, arg, &mut applicability), ), @@ -65,24 +64,21 @@ pub(super) fn check<'tcx>( cx, EXPLICIT_COUNTER_LOOP, span, - &format!("the variable `{}` is used as a loop counter", name), + &format!("the variable `{name}` is used as a loop counter"), |diag| { diag.span_suggestion( span, "consider using", format!( - "for ({}, {}) in (0_{}..).zip({})", - name, + "for ({name}, {}) in (0_{int_name}..).zip({})", snippet_with_applicability(cx, pat.span, "item", &mut applicability), - int_name, make_iterator_snippet(cx, arg, &mut applicability), ), applicability, ); diag.note(&format!( - "`{}` is of type `{}`, making it ineligible for `Iterator::enumerate`", - name, int_name + "`{name}` is of type `{int_name}`, making it ineligible for `Iterator::enumerate`" )); }, ); diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 5f5beccd030..b1f2941622a 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -41,7 +41,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, m "it is more concise to loop over references to containers instead of using explicit \ iteration methods", "to write this more concisely, try", - format!("&{}{}", muta, object), + format!("&{muta}{object}"), applicability, ); } diff --git a/clippy_lints/src/loops/for_kv_map.rs b/clippy_lints/src/loops/for_kv_map.rs index bee0e1d7683..ed620460dbe 100644 --- a/clippy_lints/src/loops/for_kv_map.rs +++ b/clippy_lints/src/loops/for_kv_map.rs @@ -38,7 +38,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx cx, FOR_KV_MAP, arg_span, - &format!("you seem to want to iterate on a map's {}s", kind), + &format!("you seem to want to iterate on a map's {kind}s"), |diag| { let map = sugg::Sugg::hir(cx, arg, "map"); multispan_sugg( @@ -46,7 +46,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx "use the corresponding method", vec![ (pat_span, snippet(cx, new_pat_span, kind).into_owned()), - (arg_span, format!("{}.{}s{}()", map.maybe_par(), kind, mutbl)), + (arg_span, format!("{}.{kind}s{mutbl}()", map.maybe_par())), ], ); }, diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 1d6ddf4b99f..1b36d452647 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -38,7 +38,7 @@ pub(super) fn check<'tcx>( then { let if_let_type = if some_ctor { "Some" } else { "Ok" }; // Prepare the error message - let msg = format!("unnecessary `if let` since only the `{}` variant of the iterator element is used", if_let_type); + let msg = format!("unnecessary `if let` since only the `{if_let_type}` variant of the iterator element is used"); // Prepare the help message let mut applicability = Applicability::MaybeIncorrect; diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 3fc569af89e..c87fc4f90e2 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -177,13 +177,7 @@ fn build_manual_memcpy_suggestion<'tcx>( let dst = if dst_offset == sugg::EMPTY && dst_limit == sugg::EMPTY { dst_base_str } else { - format!( - "{}[{}..{}]", - dst_base_str, - dst_offset.maybe_par(), - dst_limit.maybe_par() - ) - .into() + format!("{dst_base_str}[{}..{}]", dst_offset.maybe_par(), dst_limit.maybe_par()).into() }; let method_str = if is_copy(cx, elem_ty) { @@ -193,10 +187,7 @@ fn build_manual_memcpy_suggestion<'tcx>( }; format!( - "{}.{}(&{}[{}..{}]);", - dst, - method_str, - src_base_str, + "{dst}.{method_str}(&{src_base_str}[{}..{}]);", src_offset.maybe_par(), src_limit.maybe_par() ) diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index 6e6faa79adc..66f9e28596e 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -45,7 +45,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont let (arg, pred) = contains_arg .strip_prefix('&') .map_or(("&x", &*contains_arg), |s| ("x", s)); - format!("any(|{}| x == {})", arg, pred) + format!("any(|{arg}| x == {pred})") } _ => return, } @@ -141,9 +141,9 @@ impl IterFunction { IterFunctionKind::Contains(span) => { let s = snippet(cx, *span, ".."); if let Some(stripped) = s.strip_prefix('&') { - format!(".any(|x| x == {})", stripped) + format!(".any(|x| x == {stripped})") } else { - format!(".any(|x| x == *{})", s) + format!(".any(|x| x == *{s})") } }, } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 8ab640051b6..00cfc6d49f1 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -145,7 +145,7 @@ pub(super) fn check<'tcx>( cx, NEEDLESS_RANGE_LOOP, arg.span, - &format!("the loop variable `{}` is used to index `{}`", ident.name, indexed), + &format!("the loop variable `{}` is used to index `{indexed}`", ident.name), |diag| { multispan_sugg( diag, @@ -154,7 +154,7 @@ pub(super) fn check<'tcx>( (pat.span, format!("({}, )", ident.name)), ( arg.span, - format!("{}.{}().enumerate(){}{}", indexed, method, method_1, method_2), + format!("{indexed}.{method}().enumerate(){method_1}{method_2}"), ), ], ); @@ -162,16 +162,16 @@ pub(super) fn check<'tcx>( ); } else { let repl = if starts_at_zero && take_is_empty { - format!("&{}{}", ref_mut, indexed) + format!("&{ref_mut}{indexed}") } else { - format!("{}.{}(){}{}", indexed, method, method_1, method_2) + format!("{indexed}.{method}(){method_1}{method_2}") }; span_lint_and_then( cx, NEEDLESS_RANGE_LOOP, arg.span, - &format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed), + &format!("the loop variable `{}` is only used to index `{indexed}`", ident.name), |diag| { multispan_sugg( diag, diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 2386f4f4f4e..16b00ad6637 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -222,9 +222,5 @@ fn for_to_if_let_sugg(cx: &LateContext<'_>, iterator: &Expr<'_>, pat: &Pat<'_>) let pat_snippet = snippet(cx, pat.span, "_"); let iter_snippet = make_iterator_snippet(cx, iterator, &mut Applicability::Unspecified); - format!( - "if let Some({pat}) = {iter}.next()", - pat = pat_snippet, - iter = iter_snippet - ) + format!("if let Some({pat_snippet}) = {iter_snippet}.next()") } diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index aeefe6e33fb..07edee46fa6 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -30,10 +30,7 @@ pub(super) fn check<'tcx>( vec.span, "it looks like the same item is being pushed into this Vec", None, - &format!( - "try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})", - item_str, vec_str, item_str - ), + &format!("try using vec![{item_str};SIZE] or {vec_str}.resize(NEW_SIZE, {item_str})"), ); } diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 4801a84eb92..b332e8a923b 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -344,9 +344,8 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic _ => arg, }; format!( - "{}.{}()", + "{}.{method_name}()", sugg::Sugg::hir_with_applicability(cx, caller, "_", applic_ref).maybe_par(), - method_name, ) }, _ => format!( diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index deb21894f36..1c6f0264cb5 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -67,7 +67,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { expr.span.with_hi(scrutinee_expr.span.hi()), "this loop could be written as a `for` loop", "try", - format!("for {} in {}{}", loop_var, iterator, by_ref), + format!("for {loop_var} in {iterator}{by_ref}"), applicability, ); } diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 6b78c162065..f5617a905ff 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -190,9 +190,9 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { let mut suggestions = vec![]; for ((root, span, hir_id), path) in used { if path.len() == 1 { - suggestions.push((span, format!("{}::{}", root, path[0]), hir_id)); + suggestions.push((span, format!("{root}::{}", path[0]), hir_id)); } else { - suggestions.push((span, format!("{}::{{{}}}", root, path.join(", ")), hir_id)); + suggestions.push((span, format!("{root}::{{{}}}", path.join(", ")), hir_id)); } } @@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { // such as `std::prelude::v1::foo` or some other macro that expands to an import. if self.mac_refs.is_empty() { for (span, import, hir_id) in suggestions { - let help = format!("use {};", import); + let help = format!("use {import};"); span_lint_hir_and_then( cx, MACRO_USE_IMPORTS, diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 2502c8f880d..ddd9f34cbc4 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -74,11 +74,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { if let Some(ret_pos) = position_before_rarrow(&header_snip); if let Some((ret_sugg, ret_snip)) = suggested_ret(cx, output); then { - let help = format!("make the function `async` and {}", ret_sugg); + let help = format!("make the function `async` and {ret_sugg}"); diag.span_suggestion( header_span, &help, - format!("async {}{}", &header_snip[..ret_pos], ret_snip), + format!("async {}{ret_snip}", &header_snip[..ret_pos]), Applicability::MachineApplicable ); @@ -196,7 +196,7 @@ fn suggested_ret(cx: &LateContext<'_>, output: &Ty<'_>) -> Option<(&'static str, }, _ => { let sugg = "return the output of the future directly"; - snippet_opt(cx, output.span).map(|snip| (sugg, format!(" -> {}", snip))) + snippet_opt(cx, output.span).map(|snip| (sugg, format!(" -> {snip}"))) }, } } diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 2b04475c7a9..7d4f0b02112 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -133,7 +133,7 @@ impl EarlyLintPass for ManualNonExhaustiveStruct { diag.span_suggestion( header_span, "add the attribute", - format!("#[non_exhaustive] {}", snippet), + format!("#[non_exhaustive] {snippet}"), Applicability::Unspecified, ); } @@ -207,7 +207,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { diag.span_suggestion( header_span, "add the attribute", - format!("#[non_exhaustive] {}", snippet), + format!("#[non_exhaustive] {snippet}"), Applicability::Unspecified, ); } diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 8476197bd12..570fe736818 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -153,7 +153,7 @@ fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::E && let [filter_params] = filter_body.params && let Some(sugg) = match filter_params.pat.kind { hir::PatKind::Binding(_, _, filter_param_ident, None) => { - Some(format!("{}.retain(|{}| {})", snippet(cx, left_expr.span, ".."), filter_param_ident, snippet(cx, filter_body.value.span, ".."))) + Some(format!("{}.retain(|{filter_param_ident}| {})", snippet(cx, left_expr.span, ".."), snippet(cx, filter_body.value.span, ".."))) }, hir::PatKind::Tuple([key_pat, value_pat], _) => { make_sugg(cx, key_pat, value_pat, left_expr, filter_body) @@ -161,7 +161,7 @@ fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::E hir::PatKind::Ref(pat, _) => { match pat.kind { hir::PatKind::Binding(_, _, filter_param_ident, None) => { - Some(format!("{}.retain(|{}| {})", snippet(cx, left_expr.span, ".."), filter_param_ident, snippet(cx, filter_body.value.span, ".."))) + Some(format!("{}.retain(|{filter_param_ident}| {})", snippet(cx, left_expr.span, ".."), snippet(cx, filter_body.value.span, ".."))) }, _ => None } @@ -190,23 +190,19 @@ fn make_sugg( match (&key_pat.kind, &value_pat.kind) { (hir::PatKind::Binding(_, _, key_param_ident, None), hir::PatKind::Binding(_, _, value_param_ident, None)) => { Some(format!( - "{}.retain(|{}, &mut {}| {})", + "{}.retain(|{key_param_ident}, &mut {value_param_ident}| {})", snippet(cx, left_expr.span, ".."), - key_param_ident, - value_param_ident, snippet(cx, filter_body.value.span, "..") )) }, (hir::PatKind::Binding(_, _, key_param_ident, None), hir::PatKind::Wild) => Some(format!( - "{}.retain(|{}, _| {})", + "{}.retain(|{key_param_ident}, _| {})", snippet(cx, left_expr.span, ".."), - key_param_ident, snippet(cx, filter_body.value.span, "..") )), (hir::PatKind::Wild, hir::PatKind::Binding(_, _, value_param_ident, None)) => Some(format!( - "{}.retain(|_, &mut {}| {})", + "{}.retain(|_, &mut {value_param_ident}| {})", snippet(cx, left_expr.span, ".."), - value_param_ident, snippet(cx, filter_body.value.span, "..") )), _ => None, diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 7941c8c9c7e..0976940afac 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -108,15 +108,14 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { }; let test_span = expr.span.until(then.span); - span_lint_and_then(cx, MANUAL_STRIP, strippings[0], &format!("stripping a {} manually", kind_word), |diag| { - diag.span_note(test_span, &format!("the {} was tested here", kind_word)); + span_lint_and_then(cx, MANUAL_STRIP, strippings[0], &format!("stripping a {kind_word} manually"), |diag| { + diag.span_note(test_span, &format!("the {kind_word} was tested here")); multispan_sugg( diag, - &format!("try using the `strip_{}` method", kind_word), + &format!("try using the `strip_{kind_word}` method"), vec![(test_span, - format!("if let Some() = {}.strip_{}({}) ", + format!("if let Some() = {}.strip_{kind_word}({}) ", snippet(cx, target_arg.span, ".."), - kind_word, snippet(cx, pattern.span, "..")))] .into_iter().chain(strippings.into_iter().map(|span| (span, "".into()))), ); diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 33d74481529..df5684541e9 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -194,10 +194,7 @@ fn let_binding_name(cx: &LateContext<'_>, var_arg: &hir::Expr<'_>) -> String { #[must_use] fn suggestion_msg(function_type: &str, map_type: &str) -> String { - format!( - "called `map(f)` on an `{0}` value where `f` is a {1} that returns the unit type `()`", - map_type, function_type - ) + format!("called `map(f)` on an `{map_type}` value where `f` is a {function_type} that returns the unit type `()`") } fn lint_map_unit_fn( diff --git a/clippy_lints/src/match_result_ok.rs b/clippy_lints/src/match_result_ok.rs index 8588ab1ed8d..a020282d234 100644 --- a/clippy_lints/src/match_result_ok.rs +++ b/clippy_lints/src/match_result_ok.rs @@ -70,9 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk { let some_expr_string = snippet_with_applicability(cx, y[0].span, "", &mut applicability); let trimmed_ok = snippet_with_applicability(cx, let_expr.span.until(ok_path.ident.span), "", &mut applicability); let sugg = format!( - "{} let Ok({}) = {}", - ifwhile, - some_expr_string, + "{ifwhile} let Ok({some_expr_string}) = {}", trimmed_ok.trim().trim_end_matches('.'), ); span_lint_and_sugg( @@ -80,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk { MATCH_RESULT_OK, expr.span.with_hi(let_expr.span.hi()), "matching on `Some` with `ok()` is redundant", - &format!("consider matching on `Ok({})` and removing the call to `ok` instead", some_expr_string), + &format!("consider matching on `Ok({some_expr_string})` and removing the call to `ok` instead"), sugg, applicability, ); diff --git a/clippy_lints/src/matches/manual_map.rs b/clippy_lints/src/matches/manual_map.rs index b0198e856d5..96b8339550c 100644 --- a/clippy_lints/src/matches/manual_map.rs +++ b/clippy_lints/src/matches/manual_map.rs @@ -144,7 +144,7 @@ fn check<'tcx>( let scrutinee = peel_hir_expr_refs(scrutinee).0; let (scrutinee_str, _) = snippet_with_context(cx, scrutinee.span, expr_ctxt, "..", &mut app); let scrutinee_str = if scrutinee.span.ctxt() == expr.span.ctxt() && scrutinee.precedence().order() < PREC_POSTFIX { - format!("({})", scrutinee_str) + format!("({scrutinee_str})") } else { scrutinee_str.into() }; @@ -172,9 +172,9 @@ fn check<'tcx>( }; let expr_snip = snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0; if some_expr.needs_unsafe_block { - format!("|{}{}| unsafe {{ {} }}", annotation, some_binding, expr_snip) + format!("|{annotation}{some_binding}| unsafe {{ {expr_snip} }}") } else { - format!("|{}{}| {}", annotation, some_binding, expr_snip) + format!("|{annotation}{some_binding}| {expr_snip}") } } } @@ -183,9 +183,9 @@ fn check<'tcx>( let pat_snip = snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0; let expr_snip = snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0; if some_expr.needs_unsafe_block { - format!("|{}| unsafe {{ {} }}", pat_snip, expr_snip) + format!("|{pat_snip}| unsafe {{ {expr_snip} }}") } else { - format!("|{}| {}", pat_snip, expr_snip) + format!("|{pat_snip}| {expr_snip}") } } else { // Refutable bindings and mixed reference annotations can't be handled by `map`. @@ -199,9 +199,9 @@ fn check<'tcx>( "manual implementation of `Option::map`", "try this", if else_pat.is_none() && is_else_clause(cx.tcx, expr) { - format!("{{ {}{}.map({}) }}", scrutinee_str, as_ref_str, body_str) + format!("{{ {scrutinee_str}{as_ref_str}.map({body_str}) }}") } else { - format!("{}{}.map({})", scrutinee_str, as_ref_str, body_str) + format!("{scrutinee_str}{as_ref_str}.map({body_str})") }, app, ); diff --git a/clippy_lints/src/matches/manual_unwrap_or.rs b/clippy_lints/src/matches/manual_unwrap_or.rs index e1111c80f2f..2fe7fe98a2e 100644 --- a/clippy_lints/src/matches/manual_unwrap_or.rs +++ b/clippy_lints/src/matches/manual_unwrap_or.rs @@ -42,12 +42,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, scrutinee: span_lint_and_sugg( cx, MANUAL_UNWRAP_OR, expr.span, - &format!("this pattern reimplements `{}::unwrap_or`", ty_name), + &format!("this pattern reimplements `{ty_name}::unwrap_or`"), "replace with", format!( - "{}.unwrap_or({})", - suggestion, - reindented_or_body, + "{suggestion}.unwrap_or({reindented_or_body})", ), Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/matches/match_as_ref.rs b/clippy_lints/src/matches/match_as_ref.rs index 91d17f481e2..39d30212f36 100644 --- a/clippy_lints/src/matches/match_as_ref.rs +++ b/clippy_lints/src/matches/match_as_ref.rs @@ -45,13 +45,11 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: cx, MATCH_AS_REF, expr.span, - &format!("use `{}()` instead", suggestion), + &format!("use `{suggestion}()` instead"), "try this", format!( - "{}.{}(){}", + "{}.{suggestion}(){cast}", snippet_with_applicability(cx, ex.span, "_", &mut applicability), - suggestion, - cast, ), applicability, ); diff --git a/clippy_lints/src/matches/match_like_matches.rs b/clippy_lints/src/matches/match_like_matches.rs index 34cc082687e..107fad32393 100644 --- a/clippy_lints/src/matches/match_like_matches.rs +++ b/clippy_lints/src/matches/match_like_matches.rs @@ -112,7 +112,7 @@ where .join(" | ") }; let pat_and_guard = if let Some(Guard::If(g)) = first_guard { - format!("{} if {}", pat, snippet_with_applicability(cx, g.span, "..", &mut applicability)) + format!("{pat} if {}", snippet_with_applicability(cx, g.span, "..", &mut applicability)) } else { pat }; @@ -131,10 +131,9 @@ where &format!("{} expression looks like `matches!` macro", if is_if_let { "if let .. else" } else { "match" }), "try this", format!( - "{}matches!({}, {})", + "{}matches!({}, {pat_and_guard})", if b0 { "" } else { "!" }, snippet_with_applicability(cx, ex_new.span, "..", &mut applicability), - pat_and_guard, ), applicability, ); diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index e32ef9933af..3e11016602b 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -135,7 +135,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { diag.span_suggestion( keep_arm.pat.span, "try merging the arm patterns", - format!("{} | {}", keep_pat_snip, move_pat_snip), + format!("{keep_pat_snip} | {move_pat_snip}"), Applicability::MaybeIncorrect, ) .help("or try changing either arm body") diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs index 5ae4a65acaf..68682cedf1d 100644 --- a/clippy_lints/src/matches/match_single_binding.rs +++ b/clippy_lints/src/matches/match_single_binding.rs @@ -75,12 +75,11 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e Some(AssignmentExpr::Local { span, pat_span }) => ( span, format!( - "let {} = {};\n{}let {} = {};", + "let {} = {};\n{}let {} = {snippet_body};", snippet_with_applicability(cx, bind_names, "..", &mut applicability), snippet_with_applicability(cx, matched_vars, "..", &mut applicability), " ".repeat(indent_of(cx, expr.span).unwrap_or(0)), - snippet_with_applicability(cx, pat_span, "..", &mut applicability), - snippet_body + snippet_with_applicability(cx, pat_span, "..", &mut applicability) ), ), None => { @@ -110,10 +109,8 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e if ex.can_have_side_effects() { let indent = " ".repeat(indent_of(cx, expr.span).unwrap_or(0)); let sugg = format!( - "{};\n{}{}", - snippet_with_applicability(cx, ex.span, "..", &mut applicability), - indent, - snippet_body + "{};\n{indent}{snippet_body}", + snippet_with_applicability(cx, ex.span, "..", &mut applicability) ); span_lint_and_sugg( @@ -178,10 +175,10 @@ fn sugg_with_curlies<'a>( let (mut cbrace_start, mut cbrace_end) = (String::new(), String::new()); if let Some(parent_expr) = get_parent_expr(cx, match_expr) { if let ExprKind::Closure { .. } = parent_expr.kind { - cbrace_end = format!("\n{}}}", indent); + cbrace_end = format!("\n{indent}}}"); // Fix body indent due to the closure indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0)); - cbrace_start = format!("{{\n{}", indent); + cbrace_start = format!("{{\n{indent}"); } } @@ -190,10 +187,10 @@ fn sugg_with_curlies<'a>( let parent_node_id = cx.tcx.hir().get_parent_node(match_expr.hir_id); if let Node::Arm(arm) = &cx.tcx.hir().get(parent_node_id) { if let ExprKind::Match(..) = arm.body.kind { - cbrace_end = format!("\n{}}}", indent); + cbrace_end = format!("\n{indent}}}"); // Fix body indent due to the match indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0)); - cbrace_start = format!("{{\n{}", indent); + cbrace_start = format!("{{\n{indent}"); } } @@ -204,13 +201,8 @@ fn sugg_with_curlies<'a>( }); format!( - "{}let {} = {};\n{}{}{}{}", - cbrace_start, + "{cbrace_start}let {} = {};\n{indent}{assignment_str}{snippet_body}{cbrace_end}", snippet_with_applicability(cx, bind_names, "..", applicability), - snippet_with_applicability(cx, matched_vars, "..", applicability), - indent, - assignment_str, - snippet_body, - cbrace_end + snippet_with_applicability(cx, matched_vars, "..", applicability) ) } diff --git a/clippy_lints/src/matches/match_str_case_mismatch.rs b/clippy_lints/src/matches/match_str_case_mismatch.rs index 1e80b6cf2d8..6647322caa3 100644 --- a/clippy_lints/src/matches/match_str_case_mismatch.rs +++ b/clippy_lints/src/matches/match_str_case_mismatch.rs @@ -118,8 +118,8 @@ fn lint(cx: &LateContext<'_>, case_method: &CaseMethod, bad_case_span: Span, bad MATCH_STR_CASE_MISMATCH, bad_case_span, "this `match` arm has a differing case than its expression", - &format!("consider changing the case of this arm to respect `{}`", method_str), - format!("\"{}\"", suggestion), + &format!("consider changing the case of this arm to respect `{method_str}`"), + format!("\"{suggestion}\""), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/matches/match_wild_err_arm.rs b/clippy_lints/src/matches/match_wild_err_arm.rs index a3aa2e4b389..42f1e2629d4 100644 --- a/clippy_lints/src/matches/match_wild_err_arm.rs +++ b/clippy_lints/src/matches/match_wild_err_arm.rs @@ -38,7 +38,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<' span_lint_and_note(cx, MATCH_WILD_ERR_ARM, arm.pat.span, - &format!("`Err({})` matches all errors", ident_bind_name), + &format!("`Err({ident_bind_name})` matches all errors"), None, "match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable", ); diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index f7443471e31..343b1d058b4 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -138,7 +138,7 @@ fn find_sugg_for_if_let<'tcx>( cx, REDUNDANT_PATTERN_MATCHING, let_pat.span, - &format!("redundant pattern matching, consider using `{}`", good_method), + &format!("redundant pattern matching, consider using `{good_method}`"), |diag| { // if/while let ... = ... { ... } // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +162,7 @@ fn find_sugg_for_if_let<'tcx>( .maybe_par() .to_string(); - diag.span_suggestion(span, "try this", format!("{} {}.{}", keyword, sugg, good_method), app); + diag.span_suggestion(span, "try this", format!("{keyword} {sugg}.{good_method}"), app); if needs_drop { diag.note("this will change drop order of the result, as well as all temporaries"); @@ -252,12 +252,12 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op cx, REDUNDANT_PATTERN_MATCHING, expr.span, - &format!("redundant pattern matching, consider using `{}`", good_method), + &format!("redundant pattern matching, consider using `{good_method}`"), |diag| { diag.span_suggestion( span, "try this", - format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method), + format!("{}.{good_method}", snippet(cx, result_expr.span, "_")), Applicability::MaybeIncorrect, // snippet ); }, diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 86a9df03497..85269e533a0 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -50,13 +50,13 @@ fn set_diagnostic<'tcx>(diag: &mut Diagnostic, cx: &LateContext<'tcx>, expr: &'t let trailing_indent = " ".repeat(indent_of(cx, found.found_span).unwrap_or(0)); let replacement = if found.lint_suggestion == LintSuggestion::MoveAndDerefToCopy { - format!("let value = *{};\n{}", original, trailing_indent) + format!("let value = *{original};\n{trailing_indent}") } else if found.is_unit_return_val { // If the return value of the expression to be moved is unit, then we don't need to // capture the result in a temporary -- we can just replace it completely with `()`. - format!("{};\n{}", original, trailing_indent) + format!("{original};\n{trailing_indent}") } else { - format!("let value = {};\n{}", original, trailing_indent) + format!("let value = {original};\n{trailing_indent}") }; let suggestion_message = if found.lint_suggestion == LintSuggestion::MoveOnly { diff --git a/clippy_lints/src/matches/single_match.rs b/clippy_lints/src/matches/single_match.rs index 38df69eeb37..6314959f818 100644 --- a/clippy_lints/src/matches/single_match.rs +++ b/clippy_lints/src/matches/single_match.rs @@ -99,23 +99,21 @@ fn report_single_pattern( let msg = "you seem to be trying to use `match` for an equality check. Consider using `if`"; let sugg = format!( - "if {} == {}{} {}{}", + "if {} == {}{} {}{els_str}", snippet(cx, ex.span, ".."), // PartialEq for different reference counts may not exist. "&".repeat(ref_count_diff), snippet(cx, arms[0].pat.span, ".."), expr_block(cx, arms[0].body, None, "..", Some(expr.span)), - els_str, ); (msg, sugg) } else { let msg = "you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`"; let sugg = format!( - "if let {} = {} {}{}", + "if let {} = {} {}{els_str}", snippet(cx, arms[0].pat.span, ".."), snippet(cx, ex.span, ".."), expr_block(cx, arms[0].body, None, "..", Some(expr.span)), - els_str, ); (msg, sugg) } diff --git a/clippy_lints/src/matches/try_err.rs b/clippy_lints/src/matches/try_err.rs index 663277d1136..a3ec1ff2482 100644 --- a/clippy_lints/src/matches/try_err.rs +++ b/clippy_lints/src/matches/try_err.rs @@ -61,9 +61,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine "return " }; let suggestion = if err_ty == expr_err_ty { - format!("{}{}{}{}", ret_prefix, prefix, origin_snippet, suffix) + format!("{ret_prefix}{prefix}{origin_snippet}{suffix}") } else { - format!("{}{}{}.into(){}", ret_prefix, prefix, origin_snippet, suffix) + format!("{ret_prefix}{prefix}{origin_snippet}.into(){suffix}") }; span_lint_and_sugg( diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 22f5635a5bc..cc26b0f7fa8 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -85,7 +85,7 @@ pub(crate) trait BindInsteadOfMap { let closure_args_snip = snippet(cx, closure_args_span, ".."); let option_snip = snippet(cx, recv.span, ".."); - let note = format!("{}.{}({} {})", option_snip, Self::GOOD_METHOD_NAME, closure_args_snip, some_inner_snip); + let note = format!("{option_snip}.{}({closure_args_snip} {some_inner_snip})", Self::GOOD_METHOD_NAME); span_lint_and_sugg( cx, BIND_INSTEAD_OF_MAP, diff --git a/clippy_lints/src/methods/bytes_nth.rs b/clippy_lints/src/methods/bytes_nth.rs index 44857d61fef..2e96346be97 100644 --- a/clippy_lints/src/methods/bytes_nth.rs +++ b/clippy_lints/src/methods/bytes_nth.rs @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E cx, BYTES_NTH, expr.span, - &format!("called `.bytes().nth()` on a `{}`", caller_type), + &format!("called `.bytes().nth()` on a `{caller_type}`"), "try", format!( "{}.as_bytes().get({})", diff --git a/clippy_lints/src/methods/chars_cmp.rs b/clippy_lints/src/methods/chars_cmp.rs index b2bc1ad5c9e..56b7fbb9d4b 100644 --- a/clippy_lints/src/methods/chars_cmp.rs +++ b/clippy_lints/src/methods/chars_cmp.rs @@ -33,12 +33,11 @@ pub(super) fn check( cx, lint, info.expr.span, - &format!("you should use the `{}` method", suggest), + &format!("you should use the `{suggest}` method"), "like this", - format!("{}{}.{}({})", + format!("{}{}.{suggest}({})", if info.eq { "" } else { "!" }, snippet_with_applicability(cx, args[0].0.span, "..", &mut applicability), - suggest, snippet_with_applicability(cx, arg_char.span, "..", &mut applicability)), applicability, ); diff --git a/clippy_lints/src/methods/chars_cmp_with_unwrap.rs b/clippy_lints/src/methods/chars_cmp_with_unwrap.rs index b85bfec2b12..7e808760663 100644 --- a/clippy_lints/src/methods/chars_cmp_with_unwrap.rs +++ b/clippy_lints/src/methods/chars_cmp_with_unwrap.rs @@ -26,12 +26,11 @@ pub(super) fn check<'tcx>( cx, lint, info.expr.span, - &format!("you should use the `{}` method", suggest), + &format!("you should use the `{suggest}` method"), "like this", - format!("{}{}.{}('{}')", + format!("{}{}.{suggest}('{}')", if info.eq { "" } else { "!" }, snippet_with_applicability(cx, args[0].0.span, "..", &mut applicability), - suggest, c.escape_default()), applicability, ); diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 7ab6b84c207..7c7938dd2e8 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -49,8 +49,7 @@ pub(super) fn check( expr.span, &format!( "using `clone` on a double-reference; \ - this will copy the reference of type `{}` instead of cloning the inner type", - ty + this will copy the reference of type `{ty}` instead of cloning the inner type" ), |diag| { if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) { @@ -62,11 +61,11 @@ pub(super) fn check( } let refs = "&".repeat(n + 1); let derefs = "*".repeat(n); - let explicit = format!("<{}{}>::clone({})", refs, ty, snip); + let explicit = format!("<{refs}{ty}>::clone({snip})"); diag.span_suggestion( expr.span, "try dereferencing it", - format!("{}({}{}).clone()", refs, derefs, snip.deref()), + format!("{refs}({derefs}{}).clone()", snip.deref()), Applicability::MaybeIncorrect, ); diag.span_suggestion( @@ -121,16 +120,16 @@ pub(super) fn check( let (help, sugg) = if deref_count == 0 { ("try removing the `clone` call", snip.into()) } else if parent_is_suffix_expr { - ("try dereferencing it", format!("({}{})", "*".repeat(deref_count), snip)) + ("try dereferencing it", format!("({}{snip})", "*".repeat(deref_count))) } else { - ("try dereferencing it", format!("{}{}", "*".repeat(deref_count), snip)) + ("try dereferencing it", format!("{}{snip}", "*".repeat(deref_count))) }; span_lint_and_sugg( cx, CLONE_ON_COPY, expr.span, - &format!("using `clone` on type `{}` which implements the `Copy` trait", ty), + &format!("using `clone` on type `{ty}` which implements the `Copy` trait"), help, sugg, app, diff --git a/clippy_lints/src/methods/clone_on_ref_ptr.rs b/clippy_lints/src/methods/clone_on_ref_ptr.rs index f82ca891200..355f53532e2 100644 --- a/clippy_lints/src/methods/clone_on_ref_ptr.rs +++ b/clippy_lints/src/methods/clone_on_ref_ptr.rs @@ -41,7 +41,7 @@ pub(super) fn check( expr.span, "using `.clone()` on a ref-counted pointer", "try this", - format!("{}::<{}>::clone(&{})", caller_type, subst.type_at(0), snippet), + format!("{caller_type}::<{}>::clone(&{snippet})", subst.type_at(0)), Applicability::Unspecified, // Sometimes unnecessary ::<_> after Rc/Arc/Weak ); } diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index bd846d71d46..d0cf411dfd3 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -143,9 +143,9 @@ pub(super) fn check<'tcx>( cx, EXPECT_FUN_CALL, span_replace_word, - &format!("use of `{}` followed by a function call", name), + &format!("use of `{name}` followed by a function call"), "try this", - format!("unwrap_or_else({} panic!({}))", closure_args, sugg), + format!("unwrap_or_else({closure_args} panic!({sugg}))"), applicability, ); return; @@ -160,12 +160,9 @@ pub(super) fn check<'tcx>( cx, EXPECT_FUN_CALL, span_replace_word, - &format!("use of `{}` followed by a function call", name), + &format!("use of `{name}` followed by a function call"), "try this", - format!( - "unwrap_or_else({} {{ panic!(\"{{}}\", {}) }})", - closure_args, arg_root_snippet - ), + format!("unwrap_or_else({closure_args} {{ panic!(\"{{}}\", {arg_root_snippet}) }})"), applicability, ); } diff --git a/clippy_lints/src/methods/filetype_is_file.rs b/clippy_lints/src/methods/filetype_is_file.rs index 7b2967feb0f..60f8283c3e0 100644 --- a/clippy_lints/src/methods/filetype_is_file.rs +++ b/clippy_lints/src/methods/filetype_is_file.rs @@ -35,7 +35,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr span = expr.span; } } - let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb); - let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary); + let lint_msg = format!("`{lint_unary}FileType::is_file()` only {verb} regular files"); + let help_msg = format!("use `{help_unary}FileType::is_dir()` instead"); span_lint_and_help(cx, FILETYPE_IS_FILE, span, &lint_msg, None, &help_msg); } diff --git a/clippy_lints/src/methods/filter_map_next.rs b/clippy_lints/src/methods/filter_map_next.rs index 38ec4d8e3ab..ddf8a1f09b8 100644 --- a/clippy_lints/src/methods/filter_map_next.rs +++ b/clippy_lints/src/methods/filter_map_next.rs @@ -32,7 +32,7 @@ pub(super) fn check<'tcx>( expr.span, msg, "try this", - format!("{}.find_map({})", iter_snippet, filter_snippet), + format!("{iter_snippet}.find_map({filter_snippet})"), Applicability::MachineApplicable, ); } else { diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index bcf8d93b602..edcec0fc101 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -32,7 +32,7 @@ pub(super) fn check<'tcx>( expr.span, msg, "try this", - format!("{}.find({})", iter_snippet, filter_snippet), + format!("{iter_snippet}.find({filter_snippet})"), Applicability::MachineApplicable, ); } else { diff --git a/clippy_lints/src/methods/from_iter_instead_of_collect.rs b/clippy_lints/src/methods/from_iter_instead_of_collect.rs index 6436e28a63c..66dfce3682b 100644 --- a/clippy_lints/src/methods/from_iter_instead_of_collect.rs +++ b/clippy_lints/src/methods/from_iter_instead_of_collect.rs @@ -23,7 +23,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Exp // `expr` implements `FromIterator` trait let iter_expr = sugg::Sugg::hir(cx, &args[0], "..").maybe_par(); let turbofish = extract_turbofish(cx, expr, ty); - let sugg = format!("{}.collect::<{}>()", iter_expr, turbofish); + let sugg = format!("{iter_expr}.collect::<{turbofish}>()"); span_lint_and_sugg( cx, FROM_ITER_INSTEAD_OF_COLLECT, @@ -63,7 +63,7 @@ fn extract_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ty: Ty<'_>) -> if e == type_specifier { None } else { Some((*e).to_string()) } }).collect::>(); // join and add the type specifier at the end (i.e.: `collections::BTreeSet`) - format!("{}{}", without_ts.join("::"), type_specifier) + format!("{}{type_specifier}", without_ts.join("::")) } else { // type is not explicitly specified so wildcards are needed // i.e.: 2 wildcards in `std::collections::BTreeMap<&i32, &char>` @@ -72,7 +72,7 @@ fn extract_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ty: Ty<'_>) -> let end = ty_str.find('>').unwrap_or(ty_str.len()); let nb_wildcard = ty_str[start..end].split(',').count(); let wildcards = format!("_{}", ", _".repeat(nb_wildcard - 1)); - format!("{}<{}>", elements.join("::"), wildcards) + format!("{}<{wildcards}>", elements.join("::")) } } } diff --git a/clippy_lints/src/methods/get_first.rs b/clippy_lints/src/methods/get_first.rs index 4de77de7404..cb17af608a3 100644 --- a/clippy_lints/src/methods/get_first.rs +++ b/clippy_lints/src/methods/get_first.rs @@ -29,9 +29,9 @@ pub(super) fn check<'tcx>( cx, GET_FIRST, expr.span, - &format!("accessing first element with `{0}.get(0)`", slice_name), + &format!("accessing first element with `{slice_name}.get(0)`"), "try", - format!("{}.first()", slice_name), + format!("{slice_name}.first()"), app, ); } diff --git a/clippy_lints/src/methods/get_unwrap.rs b/clippy_lints/src/methods/get_unwrap.rs index 18e08d6ee23..ffc3a4d780e 100644 --- a/clippy_lints/src/methods/get_unwrap.rs +++ b/clippy_lints/src/methods/get_unwrap.rs @@ -71,16 +71,11 @@ pub(super) fn check<'tcx>( cx, GET_UNWRAP, span, - &format!( - "called `.get{0}().unwrap()` on a {1}. Using `[]` is more clear and more concise", - mut_str, caller_type - ), + &format!("called `.get{mut_str}().unwrap()` on a {caller_type}. Using `[]` is more clear and more concise"), "try this", format!( - "{}{}[{}]", - borrow_str, - snippet_with_applicability(cx, recv.span, "..", &mut applicability), - get_args_str + "{borrow_str}{}[{get_args_str}]", + snippet_with_applicability(cx, recv.span, "..", &mut applicability) ), applicability, ); diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 9651a52be4e..429cdc1918d 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -26,12 +26,12 @@ pub fn check(cx: &LateContext<'_>, method_name: &str, expr: &hir::Expr<'_>, recv cx, IMPLICIT_CLONE, expr.span, - &format!("implicitly cloning a `{}` by calling `{}` on its dereferenced type", ty_name, method_name), + &format!("implicitly cloning a `{ty_name}` by calling `{method_name}` on its dereferenced type"), "consider using", if ref_count > 1 { - format!("({}{}).clone()", "*".repeat(ref_count - 1), recv_snip) + format!("({}{recv_snip}).clone()", "*".repeat(ref_count - 1)) } else { - format!("{}.clone()", recv_snip) + format!("{recv_snip}.clone()") }, app, ); diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index e1c9b5248a8..e5dc3711b0b 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -34,18 +34,17 @@ pub fn check<'tcx>( cx, INEFFICIENT_TO_STRING, expr.span, - &format!("calling `to_string` on `{}`", arg_ty), + &format!("calling `to_string` on `{arg_ty}`"), |diag| { diag.help(&format!( - "`{}` implements `ToString` through a slower blanket impl, but `{}` has a fast specialization of `ToString`", - self_ty, deref_self_ty + "`{self_ty}` implements `ToString` through a slower blanket impl, but `{deref_self_ty}` has a fast specialization of `ToString`" )); let mut applicability = Applicability::MachineApplicable; let arg_snippet = snippet_with_applicability(cx, receiver.span, "..", &mut applicability); diag.span_suggestion( expr.span, "try dereferencing the receiver", - format!("({}{}).to_string()", "*".repeat(deref_count), arg_snippet), + format!("({}{arg_snippet}).to_string()", "*".repeat(deref_count)), applicability, ); }, diff --git a/clippy_lints/src/methods/into_iter_on_ref.rs b/clippy_lints/src/methods/into_iter_on_ref.rs index 11e76841e9f..be56b63506a 100644 --- a/clippy_lints/src/methods/into_iter_on_ref.rs +++ b/clippy_lints/src/methods/into_iter_on_ref.rs @@ -30,8 +30,7 @@ pub(super) fn check( INTO_ITER_ON_REF, method_span, &format!( - "this `.into_iter()` call is equivalent to `.{}()` and will not consume the `{}`", - method_name, kind, + "this `.into_iter()` call is equivalent to `.{method_name}()` and will not consume the `{kind}`", ), "call directly", method_name.to_string(), diff --git a/clippy_lints/src/methods/is_digit_ascii_radix.rs b/clippy_lints/src/methods/is_digit_ascii_radix.rs index aa176dcc8b4..304024e8066 100644 --- a/clippy_lints/src/methods/is_digit_ascii_radix.rs +++ b/clippy_lints/src/methods/is_digit_ascii_radix.rs @@ -37,12 +37,11 @@ pub(super) fn check<'tcx>( cx, IS_DIGIT_ASCII_RADIX, expr.span, - &format!("use of `char::is_digit` with literal radix of {}", num), + &format!("use of `char::is_digit` with literal radix of {num}"), "try", format!( - "{}.{}()", - snippet_with_applicability(cx, self_arg.span, "..", &mut applicability), - replacement + "{}.{replacement}()", + snippet_with_applicability(cx, self_arg.span, "..", &mut applicability) ), applicability, ); diff --git a/clippy_lints/src/methods/iter_cloned_collect.rs b/clippy_lints/src/methods/iter_cloned_collect.rs index 30d56113c6c..bde6f92b076 100644 --- a/clippy_lints/src/methods/iter_cloned_collect.rs +++ b/clippy_lints/src/methods/iter_cloned_collect.rs @@ -20,8 +20,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, method_name: &str, expr: &hir: cx, ITER_CLONED_COLLECT, to_replace, - &format!("called `iter().{}().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \ - more readable", method_name), + &format!("called `iter().{method_name}().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \ + more readable"), "try", ".to_vec()".to_string(), Applicability::MachineApplicable, diff --git a/clippy_lints/src/methods/iter_count.rs b/clippy_lints/src/methods/iter_count.rs index 052be3d8ee7..bcddc7c786a 100644 --- a/clippy_lints/src/methods/iter_count.rs +++ b/clippy_lints/src/methods/iter_count.rs @@ -37,7 +37,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E cx, ITER_COUNT, expr.span, - &format!("called `.{}().count()` on a `{}`", iter_method, caller_type), + &format!("called `.{iter_method}().count()` on a `{caller_type}`"), "try", format!( "{}.len()", diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index a7eecabd684..2244ebfb129 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -54,9 +54,9 @@ pub(super) fn check<'tcx>( cx, ITER_KV_MAP, expr.span, - &format!("iterating on a map's {}s", replacement_kind), + &format!("iterating on a map's {replacement_kind}s"), "try", - format!("{}.{}{}s()", recv_snippet, into_prefix, replacement_kind), + format!("{recv_snippet}.{into_prefix}{replacement_kind}s()"), applicability, ); } else { @@ -64,9 +64,9 @@ pub(super) fn check<'tcx>( cx, ITER_KV_MAP, expr.span, - &format!("iterating on a map's {}s", replacement_kind), + &format!("iterating on a map's {replacement_kind}s"), "try", - format!("{}.{}{}s().map(|{}| {})", recv_snippet, into_prefix, replacement_kind, binded_ident, + format!("{recv_snippet}.{into_prefix}{replacement_kind}s().map(|{binded_ident}| {})", snippet_with_applicability(cx, body_expr.span, "/* body */", &mut applicability)), applicability, ); diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index b8d1dabe007..83c1bf20346 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -37,7 +37,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal let suggest = if start_idx == 0 { format!("{}.first()", snippet_with_applicability(cx, caller_var.span, "..", &mut applicability)) } else { - format!("{}.get({})", snippet_with_applicability(cx, caller_var.span, "..", &mut applicability), start_idx) + format!("{}.get({start_idx})", snippet_with_applicability(cx, caller_var.span, "..", &mut applicability)) }; span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/iter_nth.rs b/clippy_lints/src/methods/iter_nth.rs index 80ca4c94219..ceee12784cb 100644 --- a/clippy_lints/src/methods/iter_nth.rs +++ b/clippy_lints/src/methods/iter_nth.rs @@ -32,8 +32,8 @@ pub(super) fn check<'tcx>( cx, ITER_NTH, expr.span, - &format!("called `.iter{0}().nth()` on a {1}", mut_str, caller_type), + &format!("called `.iter{mut_str}().nth()` on a {caller_type}"), None, - &format!("calling `.get{}()` is both faster and more readable", mut_str), + &format!("calling `.get{mut_str}()` is both faster and more readable"), ); } diff --git a/clippy_lints/src/methods/iter_with_drain.rs b/clippy_lints/src/methods/iter_with_drain.rs index a669cbbbcc6..3da230e12d7 100644 --- a/clippy_lints/src/methods/iter_with_drain.rs +++ b/clippy_lints/src/methods/iter_with_drain.rs @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span cx, ITER_WITH_DRAIN, span.with_hi(expr.span.hi()), - &format!("`drain(..)` used on a `{}`", ty_name), + &format!("`drain(..)` used on a `{ty_name}`"), "try this", "into_iter()".to_string(), Applicability::MaybeIncorrect, diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index ffd2f4a38b8..c5c0ace7729 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -37,9 +37,7 @@ pub(super) fn check<'tcx>( "this pattern reimplements `Option::ok_or`", "replace with", format!( - "{}.ok_or({})", - recv_snippet, - reindented_err_arg_snippet + "{recv_snippet}.ok_or({reindented_err_arg_snippet})" ), Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 0fe510beaa0..ec694cf6882 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -57,11 +57,10 @@ pub fn check( super::MANUAL_SATURATING_ARITHMETIC, expr.span, "manual saturating arithmetic", - &format!("try using `saturating_{}`", arith), + &format!("try using `saturating_{arith}`"), format!( - "{}.saturating_{}({})", + "{}.saturating_{arith}({})", snippet_with_applicability(cx, arith_lhs.span, "..", &mut applicability), - arith, snippet_with_applicability(cx, arith_rhs.span, "..", &mut applicability), ), applicability, diff --git a/clippy_lints/src/methods/manual_str_repeat.rs b/clippy_lints/src/methods/manual_str_repeat.rs index 46d2fc493f8..67e504af161 100644 --- a/clippy_lints/src/methods/manual_str_repeat.rs +++ b/clippy_lints/src/methods/manual_str_repeat.rs @@ -91,7 +91,7 @@ pub(super) fn check( collect_expr.span, "manual implementation of `str::repeat` using iterators", "try this", - format!("{}.repeat({})", val_str, count_snip), + format!("{val_str}.repeat({count_snip})"), app ) } diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 8261ef5e1ce..7ce14ec080b 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -111,11 +111,10 @@ fn lint_explicit_closure(cx: &LateContext<'_>, replace: Span, root: Span, is_cop MAP_CLONE, replace, message, - &format!("consider calling the dedicated `{}` method", sugg_method), + &format!("consider calling the dedicated `{sugg_method}` method"), format!( - "{}.{}()", + "{}.{sugg_method}()", snippet_with_applicability(cx, root, "..", &mut applicability), - sugg_method, ), applicability, ); diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index 13853dec99d..361ffcb5ef3 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -20,12 +20,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, map_ cx, MAP_FLATTEN, expr.span.with_lo(map_span.lo()), - &format!("called `map(..).flatten()` on `{}`", caller_ty_name), - &format!( - "try replacing `map` with `{}` and remove the `.flatten()`", - method_to_use - ), - format!("{}({})", method_to_use, closure_snippet), + &format!("called `map(..).flatten()` on `{caller_ty_name}`"), + &format!("try replacing `map` with `{method_to_use}` and remove the `.flatten()`"), + format!("{method_to_use}({closure_snippet})"), applicability, ); } diff --git a/clippy_lints/src/methods/map_identity.rs b/clippy_lints/src/methods/map_identity.rs index 862a9578e6f..0f25ef82ed4 100644 --- a/clippy_lints/src/methods/map_identity.rs +++ b/clippy_lints/src/methods/map_identity.rs @@ -30,7 +30,7 @@ pub(super) fn check( MAP_IDENTITY, sugg_span, "unnecessary map of the identity function", - &format!("remove the call to `{}`", name), + &format!("remove the call to `{name}`"), String::new(), Applicability::MachineApplicable, ) diff --git a/clippy_lints/src/methods/map_unwrap_or.rs b/clippy_lints/src/methods/map_unwrap_or.rs index 4a8e7ce4ddb..74fdead216b 100644 --- a/clippy_lints/src/methods/map_unwrap_or.rs +++ b/clippy_lints/src/methods/map_unwrap_or.rs @@ -65,7 +65,7 @@ pub(super) fn check<'tcx>( expr.span, msg, "try this", - format!("{}.map_or_else({}, {})", var_snippet, unwrap_snippet, map_snippet), + format!("{var_snippet}.map_or_else({unwrap_snippet}, {map_snippet})"), Applicability::MachineApplicable, ); return true; diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index c409268de76..6fb92d1c663 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -98,13 +98,12 @@ pub(super) fn check<'tcx>( format!(".as_ref().map({})", snippet(cx, map_arg.span, "..")) }; let method_hint = if is_mut { "as_deref_mut" } else { "as_deref" }; - let hint = format!("{}.{}()", snippet(cx, as_ref_recv.span, ".."), method_hint); - let suggestion = format!("try using {} instead", method_hint); + let hint = format!("{}.{method_hint}()", snippet(cx, as_ref_recv.span, "..")); + let suggestion = format!("try using {method_hint} instead"); let msg = format!( - "called `{0}` on an Option value. This can be done more directly \ - by calling `{1}` instead", - current_method, hint + "called `{current_method}` on an Option value. This can be done more directly \ + by calling `{hint}` instead" ); span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 6657cdccd01..76572425346 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -87,7 +87,7 @@ pub(super) fn check<'tcx>( expr.span, msg, "try using `map` instead", - format!("{0}.map({1} {2})", self_snippet, arg_snippet,func_snippet), + format!("{self_snippet}.map({arg_snippet} {func_snippet})"), Applicability::MachineApplicable, ); } @@ -102,7 +102,7 @@ pub(super) fn check<'tcx>( expr.span, msg, "try using `and_then` instead", - format!("{0}.and_then({1})", self_snippet, func_snippet), + format!("{self_snippet}.and_then({func_snippet})"), Applicability::MachineApplicable, ); } else if f_arg_is_some { @@ -115,7 +115,7 @@ pub(super) fn check<'tcx>( expr.span, msg, "try using `ok` instead", - format!("{0}.ok()", self_snippet), + format!("{self_snippet}.ok()"), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 3c4002a3aef..30421a6dd5a 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -65,9 +65,8 @@ pub(super) fn check<'tcx>( "map_or(, )" }; let msg = &format!( - "called `map().unwrap_or({})` on an `Option` value. \ - This can be done more directly by calling `{}` instead", - arg, suggest + "called `map().unwrap_or({arg})` on an `Option` value. \ + This can be done more directly by calling `{suggest}` instead" ); span_lint_and_then(cx, MAP_UNWRAP_OR, expr.span, msg, |diag| { @@ -82,10 +81,10 @@ pub(super) fn check<'tcx>( ]; if !unwrap_snippet_none { - suggestion.push((map_arg_span.with_hi(map_arg_span.lo()), format!("{}, ", unwrap_snippet))); + suggestion.push((map_arg_span.with_hi(map_arg_span.lo()), format!("{unwrap_snippet}, "))); } - diag.multipart_suggestion(&format!("use `{}` instead", suggest), suggestion, applicability); + diag.multipart_suggestion(&format!("use `{suggest}` instead"), suggestion, applicability); }); } } diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index b43b9258c47..6a35024d036 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -62,9 +62,9 @@ pub(super) fn check<'tcx>( cx, OR_FUN_CALL, method_span.with_hi(span.hi()), - &format!("use of `{}` followed by a call to `{}`", name, path), + &format!("use of `{name}` followed by a call to `{path}`"), "try this", - format!("{}()", sugg), + format!("{sugg}()"), Applicability::MachineApplicable, ); @@ -131,7 +131,7 @@ pub(super) fn check<'tcx>( if use_lambda { let l_arg = if fn_has_arguments { "_" } else { "" }; - format!("|{}| {}", l_arg, snippet).into() + format!("|{l_arg}| {snippet}").into() } else { snippet } @@ -141,9 +141,9 @@ pub(super) fn check<'tcx>( cx, OR_FUN_CALL, span_replace_word, - &format!("use of `{}` followed by a function call", name), + &format!("use of `{name}` followed by a function call"), "try this", - format!("{}_{}({})", name, suffix, sugg), + format!("{name}_{suffix}({sugg})"), Applicability::HasPlaceholders, ); } diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 7572ba3fe9a..324c9c17b5a 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -30,10 +30,7 @@ pub(super) fn check<'tcx>( let option_check_method = if is_some { "is_some" } else { "is_none" }; // lint if caller of search is an Iterator if is_trait_method(cx, is_some_recv, sym::Iterator) { - let msg = format!( - "called `{}()` after searching an `Iterator` with `{}`", - option_check_method, search_method - ); + let msg = format!("called `{option_check_method}()` after searching an `Iterator` with `{search_method}`"); let search_snippet = snippet(cx, search_arg.span, ".."); if search_snippet.lines().count() <= 1 { // suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()` @@ -86,8 +83,7 @@ pub(super) fn check<'tcx>( &msg, "use `!_.any()` instead", format!( - "!{}.any({})", - iter, + "!{iter}.any({})", any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str) ), applicability, @@ -119,7 +115,7 @@ pub(super) fn check<'tcx>( if is_string_or_str_slice(search_recv); if is_string_or_str_slice(search_arg); then { - let msg = format!("called `{}()` after calling `find()` on a string", option_check_method); + let msg = format!("called `{option_check_method}()` after calling `find()` on a string"); match option_check_method { "is_some" => { let mut applicability = Applicability::MachineApplicable; @@ -130,7 +126,7 @@ pub(super) fn check<'tcx>( method_span.with_hi(expr.span.hi()), &msg, "use `contains()` instead", - format!("contains({})", find_arg), + format!("contains({find_arg})"), applicability, ); }, @@ -144,7 +140,7 @@ pub(super) fn check<'tcx>( expr.span, &msg, "use `!_.contains()` instead", - format!("!{}.contains({})", string, find_arg), + format!("!{string}.contains({find_arg})"), applicability, ); }, diff --git a/clippy_lints/src/methods/single_char_insert_string.rs b/clippy_lints/src/methods/single_char_insert_string.rs index 18b6b5be175..44a7ad394fa 100644 --- a/clippy_lints/src/methods/single_char_insert_string.rs +++ b/clippy_lints/src/methods/single_char_insert_string.rs @@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir:: let base_string_snippet = snippet_with_applicability(cx, receiver.span.source_callsite(), "_", &mut applicability); let pos_arg = snippet_with_applicability(cx, args[0].span, "..", &mut applicability); - let sugg = format!("{}.insert({}, {})", base_string_snippet, pos_arg, extension_string); + let sugg = format!("{base_string_snippet}.insert({pos_arg}, {extension_string})"); span_lint_and_sugg( cx, SINGLE_CHAR_ADD_STR, diff --git a/clippy_lints/src/methods/single_char_push_string.rs b/clippy_lints/src/methods/single_char_push_string.rs index 9ea6751956a..0698bd6a0c5 100644 --- a/clippy_lints/src/methods/single_char_push_string.rs +++ b/clippy_lints/src/methods/single_char_push_string.rs @@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir:: if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[0], &mut applicability) { let base_string_snippet = snippet_with_applicability(cx, receiver.span.source_callsite(), "..", &mut applicability); - let sugg = format!("{}.push({})", base_string_snippet, extension_string); + let sugg = format!("{base_string_snippet}.push({extension_string})"); span_lint_and_sugg( cx, SINGLE_CHAR_ADD_STR, diff --git a/clippy_lints/src/methods/stable_sort_primitive.rs b/clippy_lints/src/methods/stable_sort_primitive.rs index 91951c65bb3..09c8ca4cbe4 100644 --- a/clippy_lints/src/methods/stable_sort_primitive.rs +++ b/clippy_lints/src/methods/stable_sort_primitive.rs @@ -17,11 +17,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx cx, STABLE_SORT_PRIMITIVE, e.span, - &format!("used `sort` on primitive type `{}`", slice_type), + &format!("used `sort` on primitive type `{slice_type}`"), |diag| { let mut app = Applicability::MachineApplicable; let recv_snip = snippet_with_context(cx, recv.span, e.span.ctxt(), "..", &mut app).0; - diag.span_suggestion(e.span, "try", format!("{}.sort_unstable()", recv_snip), app); + diag.span_suggestion(e.span, "try", format!("{recv_snip}.sort_unstable()"), app); diag.note( "an unstable sort typically performs faster without any observable difference for this data type", ); diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index 143dcee3505..6974260f70d 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -34,9 +34,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr "calling `.extend(_.chars())`", "try this", format!( - "{}.push_str({}{})", + "{}.push_str({ref_str}{})", snippet_with_applicability(cx, recv.span, "..", &mut applicability), - ref_str, snippet_with_applicability(cx, target.span, "..", &mut applicability) ), applicability, diff --git a/clippy_lints/src/methods/suspicious_splitn.rs b/clippy_lints/src/methods/suspicious_splitn.rs index 55567d8625e..219a9edd657 100644 --- a/clippy_lints/src/methods/suspicious_splitn.rs +++ b/clippy_lints/src/methods/suspicious_splitn.rs @@ -24,10 +24,10 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se } let (msg, note_msg) = if count == 0 { - (format!("`{}` called with `0` splits", method_name), + (format!("`{method_name}` called with `0` splits"), "the resulting iterator will always return `None`") } else { - (format!("`{}` called with `1` split", method_name), + (format!("`{method_name}` called with `1` split"), if self_ty.is_slice() { "the resulting iterator will always return the entire slice followed by `None`" } else { diff --git a/clippy_lints/src/methods/suspicious_to_owned.rs b/clippy_lints/src/methods/suspicious_to_owned.rs index 6b306fbf008..15c1c618c51 100644 --- a/clippy_lints/src/methods/suspicious_to_owned.rs +++ b/clippy_lints/src/methods/suspicious_to_owned.rs @@ -24,9 +24,9 @@ pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) - cx, SUSPICIOUS_TO_OWNED, expr.span, - &format!("this `to_owned` call clones the {0} itself and does not cause the {0} contents to become owned", input_type), + &format!("this `to_owned` call clones the {input_type} itself and does not cause the {input_type} contents to become owned"), "consider using, depending on intent", - format!("{0}.clone()` or `{0}.into_owned()", recv_snip), + format!("{recv_snip}.clone()` or `{recv_snip}.into_owned()"), app, ); return true; diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 4e8c201f470..ee16982d524 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -54,7 +54,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr< UNNECESSARY_FIND_MAP }, expr.span, - &format!("this `.{}` can be written more simply using `.{}`", name, sugg), + &format!("this `.{name}` can be written more simply using `.{sugg}`"), ); } } diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index c17ef6809f9..aa87dead38f 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -49,15 +49,12 @@ pub(super) fn check( let mut applicability = Applicability::MachineApplicable; let sugg = if replacement_has_args { format!( - "{replacement}(|{s}| {r})", - replacement = replacement_method_name, - s = second_arg_ident, + "{replacement_method_name}(|{second_arg_ident}| {r})", r = snippet_with_applicability(cx, right_expr.span, "EXPR", &mut applicability), ) } else { format!( - "{replacement}()", - replacement = replacement_method_name, + "{replacement_method_name}()", ) }; diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 95138c0e25b..1966a85f7a7 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -68,7 +68,7 @@ pub fn check_for_loop_iter( cx, UNNECESSARY_TO_OWNED, expr.span, - &format!("unnecessary use of `{}`", method_name), + &format!("unnecessary use of `{method_name}`"), |diag| { // If `check_into_iter_call_arg` called `check_for_loop_iter` because a call to // a `to_owned`-like function was removed, then the next suggestion may be diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index a187a8d6016..ec9859fa298 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -58,8 +58,8 @@ pub(super) fn check<'tcx>( span_lint_and_then(cx, UNNECESSARY_LAZY_EVALUATIONS, expr.span, msg, |diag| { diag.span_suggestion( span, - &format!("use `{}(..)` instead", simplify_using), - format!("{}({})", simplify_using, snippet(cx, body_expr.span, "..")), + &format!("use `{simplify_using}(..)` instead"), + format!("{simplify_using}({})", snippet(cx, body_expr.span, "..")), applicability, ); }); diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 8e9ed33e009..d27831327ac 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -133,12 +133,11 @@ fn check_addr_of_expr( cx, UNNECESSARY_TO_OWNED, parent.span, - &format!("unnecessary use of `{}`", method_name), + &format!("unnecessary use of `{method_name}`"), "use", format!( - "{:&>width$}{}", + "{:&>width$}{receiver_snippet}", "", - receiver_snippet, width = n_target_refs - n_receiver_refs ), Applicability::MachineApplicable, @@ -155,7 +154,7 @@ fn check_addr_of_expr( cx, UNNECESSARY_TO_OWNED, parent.span, - &format!("unnecessary use of `{}`", method_name), + &format!("unnecessary use of `{method_name}`"), "use", receiver_snippet, Applicability::MachineApplicable, @@ -165,7 +164,7 @@ fn check_addr_of_expr( cx, UNNECESSARY_TO_OWNED, expr.span.with_lo(receiver.span.hi()), - &format!("unnecessary use of `{}`", method_name), + &format!("unnecessary use of `{method_name}`"), "remove this", String::new(), Applicability::MachineApplicable, @@ -182,9 +181,9 @@ fn check_addr_of_expr( cx, UNNECESSARY_TO_OWNED, parent.span, - &format!("unnecessary use of `{}`", method_name), + &format!("unnecessary use of `{method_name}`"), "use", - format!("{}.as_ref()", receiver_snippet), + format!("{receiver_snippet}.as_ref()"), Applicability::MachineApplicable, ); return true; @@ -229,9 +228,9 @@ fn check_into_iter_call_arg( cx, UNNECESSARY_TO_OWNED, parent.span, - &format!("unnecessary use of `{}`", method_name), + &format!("unnecessary use of `{method_name}`"), "use", - format!("{}.iter().{}()", receiver_snippet, cloned_or_copied), + format!("{receiver_snippet}.iter().{cloned_or_copied}()"), Applicability::MaybeIncorrect, ); return true; @@ -276,9 +275,9 @@ fn check_other_call_arg<'tcx>( cx, UNNECESSARY_TO_OWNED, maybe_arg.span, - &format!("unnecessary use of `{}`", method_name), + &format!("unnecessary use of `{method_name}`"), "use", - format!("{:&>width$}{}", "", receiver_snippet, width = n_refs), + format!("{:&>n_refs$}{receiver_snippet}", ""), Applicability::MachineApplicable, ); return true; diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index ca5d33ee8b0..0380a82411a 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -35,7 +35,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, cx, USELESS_ASREF, expr.span, - &format!("this call to `{}` does nothing", call_name), + &format!("this call to `{call_name}` does nothing"), "try this", snippet_with_applicability(cx, recvr.span, "..", &mut applicability).to_string(), applicability, diff --git a/clippy_lints/src/methods/wrong_self_convention.rs b/clippy_lints/src/methods/wrong_self_convention.rs index 4b368d3ffae..1fbf783b886 100644 --- a/clippy_lints/src/methods/wrong_self_convention.rs +++ b/clippy_lints/src/methods/wrong_self_convention.rs @@ -61,20 +61,20 @@ impl Convention { impl fmt::Display for Convention { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { match *self { - Self::Eq(this) => format!("`{}`", this).fmt(f), - Self::StartsWith(this) => format!("`{}*`", this).fmt(f), - Self::EndsWith(this) => format!("`*{}`", this).fmt(f), - Self::NotEndsWith(this) => format!("`~{}`", this).fmt(f), + Self::Eq(this) => format!("`{this}`").fmt(f), + Self::StartsWith(this) => format!("`{this}*`").fmt(f), + Self::EndsWith(this) => format!("`*{this}`").fmt(f), + Self::NotEndsWith(this) => format!("`~{this}`").fmt(f), Self::IsSelfTypeCopy(is_true) => { format!("`self` type is{} `Copy`", if is_true { "" } else { " not" }).fmt(f) }, Self::ImplementsTrait(is_true) => { let (negation, s_suffix) = if is_true { ("", "s") } else { (" does not", "") }; - format!("method{} implement{} a trait", negation, s_suffix).fmt(f) + format!("method{negation} implement{s_suffix} a trait").fmt(f) }, Self::IsTraitItem(is_true) => { let suffix = if is_true { " is" } else { " is not" }; - format!("method{} a trait item", suffix).fmt(f) + format!("method{suffix} a trait item").fmt(f) }, } } @@ -138,8 +138,7 @@ pub(super) fn check<'tcx>( WRONG_SELF_CONVENTION, first_arg_span, &format!( - "{} usually take {}", - suggestion, + "{suggestion} usually take {}", &self_kinds .iter() .map(|k| k.description()) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index ea245edd770..381458b91e6 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -178,7 +178,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { ("", sugg_init.addr()) }; let tyopt = if let Some(ty) = local.ty { - format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "..")) + format!(": &{mutopt}{ty}", ty=snippet(cx, ty.span, "..")) } else { String::new() }; @@ -195,8 +195,6 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { format!( "let {name}{tyopt} = {initref};", name=snippet(cx, name.span, ".."), - tyopt=tyopt, - initref=initref, ), Applicability::MachineApplicable, ); @@ -222,8 +220,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { stmt.span, "replace it with", format!( - "if {} {{ {}; }}", - sugg, + "if {sugg} {{ {}; }}", &snippet(cx, b.span, ".."), ), Applicability::MachineApplicable, // snippet @@ -275,9 +272,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { USED_UNDERSCORE_BINDING, expr.span, &format!( - "used binding `{}` which is prefixed with an underscore. A leading \ - underscore signals that a binding will not be used", - binding + "used binding `{binding}` which is prefixed with an underscore. A leading \ + underscore signals that a binding will not be used" ), ); } @@ -328,12 +324,12 @@ fn check_cast(cx: &LateContext<'_>, span: Span, e: &Expr<'_>, ty: &hir::Ty<'_>) }; let (sugg, appl) = if let TyKind::Infer = mut_ty.ty.kind { - (format!("{}()", sugg_fn), Applicability::MachineApplicable) + (format!("{sugg_fn}()"), Applicability::MachineApplicable) } else if let Some(mut_ty_snip) = snippet_opt(cx, mut_ty.ty.span) { - (format!("{}::<{}>()", sugg_fn, mut_ty_snip), Applicability::MachineApplicable) + (format!("{sugg_fn}::<{mut_ty_snip}>()"), Applicability::MachineApplicable) } else { // `MaybeIncorrect` as type inference may not work with the suggested code - (format!("{}()", sugg_fn), Applicability::MaybeIncorrect) + (format!("{sugg_fn}()"), Applicability::MaybeIncorrect) }; span_lint_and_sugg(cx, ZERO_PTR, span, msg, "try", sugg, appl); } diff --git a/clippy_lints/src/misc_early/literal_suffix.rs b/clippy_lints/src/misc_early/literal_suffix.rs index 1165c19a0cf..62c6ca32d31 100644 --- a/clippy_lints/src/misc_early/literal_suffix.rs +++ b/clippy_lints/src/misc_early/literal_suffix.rs @@ -18,9 +18,9 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &s cx, SEPARATED_LITERAL_SUFFIX, lit.span, - &format!("{} type suffix should not be separated by an underscore", sugg_type), + &format!("{sugg_type} type suffix should not be separated by an underscore"), "remove the underscore", - format!("{}{}", &lit_snip[..maybe_last_sep_idx], suffix), + format!("{}{suffix}", &lit_snip[..maybe_last_sep_idx]), Applicability::MachineApplicable, ); } else { @@ -28,9 +28,9 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &s cx, UNSEPARATED_LITERAL_SUFFIX, lit.span, - &format!("{} type suffix should be separated by an underscore", sugg_type), + &format!("{sugg_type} type suffix should be separated by an underscore"), "add an underscore", - format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix), + format!("{}_{suffix}", &lit_snip[..=maybe_last_sep_idx]), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index 704918c0b97..c8227ca4450 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -357,9 +357,8 @@ impl EarlyLintPass for MiscEarlyLints { DUPLICATE_UNDERSCORE_ARGUMENT, *correspondence, &format!( - "`{}` already exists, having another argument having almost the same \ - name makes code comprehension and documentation more difficult", - arg_name + "`{arg_name}` already exists, having another argument having almost the same \ + name makes code comprehension and documentation more difficult" ), ); } diff --git a/clippy_lints/src/misc_early/unneeded_field_pattern.rs b/clippy_lints/src/misc_early/unneeded_field_pattern.rs index fff533167ed..676e5d40bb7 100644 --- a/clippy_lints/src/misc_early/unneeded_field_pattern.rs +++ b/clippy_lints/src/misc_early/unneeded_field_pattern.rs @@ -27,7 +27,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { pat.span, "all the struct fields are matched to a wildcard pattern, consider using `..`", None, - &format!("try with `{} {{ .. }}` instead", type_name), + &format!("try with `{type_name} {{ .. }}` instead"), ); return; } @@ -63,7 +63,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { "you matched a field with a wildcard pattern, consider using `..` \ instead", None, - &format!("try with `{} {{ {}, .. }}`", type_name, normal[..].join(", ")), + &format!("try with `{type_name} {{ {}, .. }}`", normal[..].join(", ")), ); } } diff --git a/clippy_lints/src/mismatching_type_param_order.rs b/clippy_lints/src/mismatching_type_param_order.rs index 020efeaebf0..6dd76a6531e 100644 --- a/clippy_lints/src/mismatching_type_param_order.rs +++ b/clippy_lints/src/mismatching_type_param_order.rs @@ -91,10 +91,9 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch { let type_name = segment.ident; for (i, (impl_param_name, impl_param_span)) in impl_params.iter().enumerate() { if mismatch_param_name(i, impl_param_name, &type_param_names_hashmap) { - let msg = format!("`{}` has a similarly named generic type parameter `{}` in its declaration, but in a different order", - type_name, impl_param_name); - let help = format!("try `{}`, or a name that does not conflict with `{}`'s generic params", - type_param_names[i], type_name); + let msg = format!("`{type_name}` has a similarly named generic type parameter `{impl_param_name}` in its declaration, but in a different order"); + let help = format!("try `{}`, or a name that does not conflict with `{type_name}`'s generic params", + type_param_names[i]); span_lint_and_help( cx, MISMATCHING_TYPE_PARAM_ORDER, diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index ee81f72a0e7..97c8fb17638 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -104,7 +104,7 @@ impl MissingDoc { cx, MISSING_DOCS_IN_PRIVATE_ITEMS, sp, - &format!("missing documentation for {} {}", article, desc), + &format!("missing documentation for {article} {desc}"), ); } } diff --git a/clippy_lints/src/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 3d0a2382283..697e6fd24dd 100644 --- a/clippy_lints/src/missing_enforced_import_rename.rs +++ b/clippy_lints/src/missing_enforced_import_rename.rs @@ -90,9 +90,7 @@ impl LateLintPass<'_> for ImportRename { "this import should be renamed", "try", format!( - "{} as {}", - import, - name, + "{import} as {name}", ), Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 07bc2ca5d3c..18c45120091 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -65,7 +65,7 @@ fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp cx, MISSING_INLINE_IN_PUBLIC_ITEMS, sp, - &format!("missing `#[inline]` for {}", desc), + &format!("missing `#[inline]` for {desc}"), ); } } diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 82dc03ef5c5..463da11774a 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -88,7 +88,7 @@ fn check_arguments<'tcx>( cx, UNNECESSARY_MUT_PASSED, argument.span, - &format!("the {} `{}` doesn't need a mutable reference", fn_kind, name), + &format!("the {fn_kind} `{name}` doesn't need a mutable reference"), ); } }, diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 321db08dfe8..3ef0c663459 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -56,10 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for DebugAssertWithMutCall { cx, DEBUG_ASSERT_WITH_MUT_CALL, span, - &format!( - "do not call a function with mutable arguments inside of `{}!`", - macro_name - ), + &format!("do not call a function with mutable arguments inside of `{macro_name}!`"), ); } } diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index a98577093ed..09cb5333176 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -84,9 +84,8 @@ impl<'tcx> LateLintPass<'tcx> for Mutex { let mutex_param = subst.type_at(0); if let Some(atomic_name) = get_atomic_name(mutex_param) { let msg = format!( - "consider using an `{}` instead of a `Mutex` here; if you just want the locking \ - behavior and not the internal type, consider using `Mutex<()>`", - atomic_name + "consider using an `{atomic_name}` instead of a `Mutex` here; if you just want the locking \ + behavior and not the internal type, consider using `Mutex<()>`" ); match *mutex_param.kind() { ty::Uint(t) if t != ty::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 98a3bce1ff3..6f0e755466e 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -309,7 +309,7 @@ fn emit_warning<'a>(cx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str, expr.span, message, None, - &format!("{}\n{}", header, snip), + &format!("{header}\n{snip}"), ); } @@ -322,10 +322,7 @@ fn suggestion_snippet_for_continue_inside_if<'a>(cx: &EarlyContext<'_>, data: &' let indent_if = indent_of(cx, data.if_expr.span).unwrap_or(0); format!( - "{indent}if {} {}\n{indent}{}", - cond_code, - continue_code, - else_code, + "{indent}if {cond_code} {continue_code}\n{indent}{else_code}", indent = " ".repeat(indent_if), ) } @@ -349,7 +346,7 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data: let span = cx.sess().source_map().stmt_span(stmt.span, data.loop_block.span); let snip = snippet_block(cx, span, "..", None).into_owned(); snip.lines() - .map(|line| format!("{}{}", " ".repeat(indent), line)) + .map(|line| format!("{}{line}", " ".repeat(indent))) .collect::>() .join("\n") }) @@ -358,10 +355,7 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data: let indent_if = indent_of(cx, data.if_expr.span).unwrap_or(0); format!( - "{indent_if}if {} {}\n{indent}// merged code follows:\n{}\n{indent_if}}}", - cond_code, - block_code, - to_annex, + "{indent_if}if {cond_code} {block_code}\n{indent}// merged code follows:\n{to_annex}\n{indent_if}}}", indent = " ".repeat(indent), indent_if = " ".repeat(indent_if), ) diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index de99f1d7078..cbad53f4450 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -287,7 +287,7 @@ fn check<'tcx>( diag.span_suggestion( assign.lhs_span, - &format!("declare `{}` here", binding_name), + &format!("declare `{binding_name}` here"), let_snippet, Applicability::MachineApplicable, ); @@ -307,8 +307,8 @@ fn check<'tcx>( diag.span_suggestion_verbose( usage.stmt.span.shrink_to_lo(), - &format!("declare `{}` here", binding_name), - format!("{} = ", let_snippet), + &format!("declare `{binding_name}` here"), + format!("{let_snippet} = "), applicability, ); @@ -338,8 +338,8 @@ fn check<'tcx>( diag.span_suggestion_verbose( usage.stmt.span.shrink_to_lo(), - &format!("declare `{}` here", binding_name), - format!("{} = ", let_snippet), + &format!("declare `{binding_name}` here"), + format!("{let_snippet} = "), applicability, ); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 6d17c7a7346..d7e6e7de2cc 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -236,7 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { snippet_opt(cx, span) .map_or( "change the call to".into(), - |x| Cow::from(format!("change `{}` to", x)), + |x| Cow::from(format!("change `{x}` to")), ) .as_ref(), suggestion, @@ -266,7 +266,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { snippet_opt(cx, span) .map_or( "change the call to".into(), - |x| Cow::from(format!("change `{}` to", x)) + |x| Cow::from(format!("change `{x}` to")) ) .as_ref(), suggestion, diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 8f85b00596c..59b6492e112 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -134,7 +134,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { NEEDLESS_QUESTION_MARK, expr.span, "question mark operator is useless here", - &format!("try removing question mark and `{}`", sugg_remove), + &format!("try removing question mark and `{sugg_remove}`"), format!("{}", snippet(cx, inner_expr.span, r#""...""#)), Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index b087cfb36b1..fb9a4abd0b4 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -62,9 +62,9 @@ fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { let mut applicability = Applicability::MachineApplicable; let snip = snippet_with_applicability(cx, exp.span, "..", &mut applicability); let suggestion = if exp.precedence().order() < PREC_PREFIX && !has_enclosing_paren(&snip) { - format!("-({})", snip) + format!("-({snip})") } else { - format!("-{}", snip) + format!("-{snip}") }; span_lint_and_sugg( cx, diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 5c45ee6d94a..cfd24e9b2d3 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -136,8 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { id, impl_item.span, &format!( - "you should consider adding a `Default` implementation for `{}`", - self_type_snip + "you should consider adding a `Default` implementation for `{self_type_snip}`" ), |diag| { diag.suggest_prepend_item( @@ -161,9 +160,9 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { fn create_new_without_default_suggest_msg(self_type_snip: &str, generics_sugg: &str) -> String { #[rustfmt::skip] format!( -"impl{} Default for {} {{ +"impl{generics_sugg} Default for {self_type_snip} {{ fn default() -> Self {{ Self::new() }} -}}", generics_sugg, self_type_snip) +}}") } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index b96af06b8d7..03fddd207ec 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -108,10 +108,7 @@ impl<'a, 'tcx> SimilarNamesLocalVisitor<'a, 'tcx> { self.cx, MANY_SINGLE_CHAR_NAMES, span, - &format!( - "{} bindings with single-character names in scope", - num_single_char_names - ), + &format!("{num_single_char_names} bindings with single-character names in scope"), ); } } diff --git a/clippy_lints/src/nonstandard_macro_braces.rs b/clippy_lints/src/nonstandard_macro_braces.rs index 5e38a95c40b..0ca0befc135 100644 --- a/clippy_lints/src/nonstandard_macro_braces.rs +++ b/clippy_lints/src/nonstandard_macro_braces.rs @@ -107,11 +107,11 @@ fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a Mac if let Some(snip) = snippet_opt(cx, span_call_site); // we must check only invocation sites // https://github.com/rust-lang/rust-clippy/issues/7422 - if snip.starts_with(&format!("{}!", name)); + if snip.starts_with(&format!("{name}!")); if unnested_or_local(); // make formatting consistent let c = snip.replace(' ', ""); - if !c.starts_with(&format!("{}!{}", name, braces.0)); + if !c.starts_with(&format!("{name}!{}", braces.0)); if !mac_braces.done.contains(&span_call_site); then { Some((span_call_site, braces, snip)) @@ -131,9 +131,9 @@ fn emit_help(cx: &EarlyContext<'_>, snip: &str, braces: &(String, String), span: cx, NONSTANDARD_MACRO_BRACES, span, - &format!("use of irregular braces for `{}!` macro", macro_name), + &format!("use of irregular braces for `{macro_name}!` macro"), "consider writing", - format!("{}!{}{}{}", macro_name, braces.0, macro_args, braces.1), + format!("{macro_name}!{}{macro_args}{}", braces.0, braces.1), Applicability::MachineApplicable, ); } @@ -266,9 +266,7 @@ impl<'de> Deserialize<'de> for MacroMatcher { .iter() .find(|b| b.0 == brace) .map(|(o, c)| ((*o).to_owned(), (*c).to_owned())) - .ok_or_else(|| { - de::Error::custom(&format!("expected one of `(`, `{{`, `[` found `{}`", brace)) - })?, + .ok_or_else(|| de::Error::custom(&format!("expected one of `(`, `{{`, `[` found `{brace}`")))?, }) } } diff --git a/clippy_lints/src/octal_escapes.rs b/clippy_lints/src/octal_escapes.rs index bffbf20b4d2..f380a506582 100644 --- a/clippy_lints/src/octal_escapes.rs +++ b/clippy_lints/src/octal_escapes.rs @@ -102,7 +102,7 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) { // construct a replacement escape // the maximum value is \077, or \x3f, so u8 is sufficient here if let Ok(n) = u8::from_str_radix(&contents[from + 1..to], 8) { - write!(suggest_1, "\\x{:02x}", n).unwrap(); + write!(suggest_1, "\\x{n:02x}").unwrap(); } // append the null byte as \x00 and the following digits literally diff --git a/clippy_lints/src/operators/absurd_extreme_comparisons.rs b/clippy_lints/src/operators/absurd_extreme_comparisons.rs index 1ec4240afef..d29ca37eaeb 100644 --- a/clippy_lints/src/operators/absurd_extreme_comparisons.rs +++ b/clippy_lints/src/operators/absurd_extreme_comparisons.rs @@ -34,13 +34,12 @@ pub(super) fn check<'tcx>( }; let help = format!( - "because `{}` is the {} value for this type, {}", + "because `{}` is the {} value for this type, {conclusion}", snippet(cx, culprit.expr.span, "x"), match culprit.which { ExtremeType::Minimum => "minimum", ExtremeType::Maximum => "maximum", - }, - conclusion + } ); span_lint_and_help(cx, ABSURD_EXTREME_COMPARISONS, expr.span, msg, None, &help); diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 945a09a647c..cb5abfb809e 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -55,7 +55,7 @@ pub(super) fn check<'tcx>( diag.span_suggestion( expr.span, "replace it with", - format!("{} {}= {}", snip_a, op.node.as_str(), snip_r), + format!("{snip_a} {}= {snip_r}", op.node.as_str()), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/operators/bit_mask.rs b/clippy_lints/src/operators/bit_mask.rs index 74387fbc87b..1369b3e7462 100644 --- a/clippy_lints/src/operators/bit_mask.rs +++ b/clippy_lints/src/operators/bit_mask.rs @@ -64,10 +64,7 @@ fn check_bit_mask( cx, BAD_BIT_MASK, span, - &format!( - "incompatible bit mask: `_ & {}` can never be equal to `{}`", - mask_value, cmp_value - ), + &format!("incompatible bit mask: `_ & {mask_value}` can never be equal to `{cmp_value}`"), ); } } else if mask_value == 0 { @@ -80,10 +77,7 @@ fn check_bit_mask( cx, BAD_BIT_MASK, span, - &format!( - "incompatible bit mask: `_ | {}` can never be equal to `{}`", - mask_value, cmp_value - ), + &format!("incompatible bit mask: `_ | {mask_value}` can never be equal to `{cmp_value}`"), ); } }, @@ -96,10 +90,7 @@ fn check_bit_mask( cx, BAD_BIT_MASK, span, - &format!( - "incompatible bit mask: `_ & {}` will always be lower than `{}`", - mask_value, cmp_value - ), + &format!("incompatible bit mask: `_ & {mask_value}` will always be lower than `{cmp_value}`"), ); } else if mask_value == 0 { span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); @@ -111,10 +102,7 @@ fn check_bit_mask( cx, BAD_BIT_MASK, span, - &format!( - "incompatible bit mask: `_ | {}` will never be lower than `{}`", - mask_value, cmp_value - ), + &format!("incompatible bit mask: `_ | {mask_value}` will never be lower than `{cmp_value}`"), ); } else { check_ineffective_lt(cx, span, mask_value, cmp_value, "|"); @@ -130,10 +118,7 @@ fn check_bit_mask( cx, BAD_BIT_MASK, span, - &format!( - "incompatible bit mask: `_ & {}` will never be higher than `{}`", - mask_value, cmp_value - ), + &format!("incompatible bit mask: `_ & {mask_value}` will never be higher than `{cmp_value}`"), ); } else if mask_value == 0 { span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); @@ -145,10 +130,7 @@ fn check_bit_mask( cx, BAD_BIT_MASK, span, - &format!( - "incompatible bit mask: `_ | {}` will always be higher than `{}`", - mask_value, cmp_value - ), + &format!("incompatible bit mask: `_ | {mask_value}` will always be higher than `{cmp_value}`"), ); } else { check_ineffective_gt(cx, span, mask_value, cmp_value, "|"); @@ -167,10 +149,7 @@ fn check_ineffective_lt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: cx, INEFFECTIVE_BIT_MASK, span, - &format!( - "ineffective bit mask: `x {} {}` compared to `{}`, is the same as x compared directly", - op, m, c - ), + &format!("ineffective bit mask: `x {op} {m}` compared to `{c}`, is the same as x compared directly"), ); } } @@ -181,10 +160,7 @@ fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: cx, INEFFECTIVE_BIT_MASK, span, - &format!( - "ineffective bit mask: `x {} {}` compared to `{}`, is the same as x compared directly", - op, m, c - ), + &format!("ineffective bit mask: `x {op} {m}` compared to `{c}`, is the same as x compared directly"), ); } } diff --git a/clippy_lints/src/operators/cmp_owned.rs b/clippy_lints/src/operators/cmp_owned.rs index 638a514ff9b..c9c777f1bd8 100644 --- a/clippy_lints/src/operators/cmp_owned.rs +++ b/clippy_lints/src/operators/cmp_owned.rs @@ -99,7 +99,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) let expr_snip; let eq_impl; if with_deref.is_implemented() { - expr_snip = format!("*{}", arg_snip); + expr_snip = format!("*{arg_snip}"); eq_impl = with_deref; } else { expr_snip = arg_snip.to_string(); @@ -121,17 +121,15 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) }; if eq_impl.ty_eq_other { hint = format!( - "{}{}{}", - expr_snip, + "{expr_snip}{}{}", snippet(cx, cmp_span, ".."), snippet(cx, other.span, "..") ); } else { hint = format!( - "{}{}{}", + "{}{}{expr_snip}", snippet(cx, other.span, ".."), - snippet(cx, cmp_span, ".."), - expr_snip + snippet(cx, cmp_span, "..") ); } } diff --git a/clippy_lints/src/operators/duration_subsec.rs b/clippy_lints/src/operators/duration_subsec.rs index 827a2b26709..49e662cacb0 100644 --- a/clippy_lints/src/operators/duration_subsec.rs +++ b/clippy_lints/src/operators/duration_subsec.rs @@ -31,12 +31,11 @@ pub(crate) fn check<'tcx>( cx, DURATION_SUBSEC, expr.span, - &format!("calling `{}()` is more concise than this calculation", suggested_fn), + &format!("calling `{suggested_fn}()` is more concise than this calculation"), "try", format!( - "{}.{}()", - snippet_with_applicability(cx, self_arg.span, "_", &mut applicability), - suggested_fn + "{}.{suggested_fn}()", + snippet_with_applicability(cx, self_arg.span, "_", &mut applicability) ), applicability, ); diff --git a/clippy_lints/src/operators/eq_op.rs b/clippy_lints/src/operators/eq_op.rs index 44cf0bb0612..67913f7392c 100644 --- a/clippy_lints/src/operators/eq_op.rs +++ b/clippy_lints/src/operators/eq_op.rs @@ -22,7 +22,7 @@ pub(crate) fn check_assert<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { cx, EQ_OP, lhs.span.to(rhs.span), - &format!("identical args used in this `{}!` macro call", macro_name), + &format!("identical args used in this `{macro_name}!` macro call"), ); } } diff --git a/clippy_lints/src/operators/misrefactored_assign_op.rs b/clippy_lints/src/operators/misrefactored_assign_op.rs index 0024384d927..ae805147f07 100644 --- a/clippy_lints/src/operators/misrefactored_assign_op.rs +++ b/clippy_lints/src/operators/misrefactored_assign_op.rs @@ -47,18 +47,14 @@ fn lint_misrefactored_assign_op( if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span)) { let a = &sugg::Sugg::hir(cx, assignee, ".."); let r = &sugg::Sugg::hir(cx, rhs, ".."); - let long = format!("{} = {}", snip_a, sugg::make_binop(op.into(), a, r)); + let long = format!("{snip_a} = {}", sugg::make_binop(op.into(), a, r)); diag.span_suggestion( expr.span, &format!( - "did you mean `{} = {} {} {}` or `{}`? Consider replacing it with", - snip_a, - snip_a, - op.as_str(), - snip_r, - long + "did you mean `{snip_a} = {snip_a} {} {snip_r}` or `{long}`? Consider replacing it with", + op.as_str() ), - format!("{} {}= {}", snip_a, op.as_str(), snip_r), + format!("{snip_a} {}= {snip_r}", op.as_str()), Applicability::MaybeIncorrect, ); diag.span_suggestion( diff --git a/clippy_lints/src/operators/needless_bitwise_bool.rs b/clippy_lints/src/operators/needless_bitwise_bool.rs index e902235a014..ab5fb178700 100644 --- a/clippy_lints/src/operators/needless_bitwise_bool.rs +++ b/clippy_lints/src/operators/needless_bitwise_bool.rs @@ -27,7 +27,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, op: BinOpKind, lhs: &Exp if let Some(lhs_snip) = snippet_opt(cx, lhs.span) && let Some(rhs_snip) = snippet_opt(cx, rhs.span) { - let sugg = format!("{} {} {}", lhs_snip, op_str, rhs_snip); + let sugg = format!("{lhs_snip} {op_str} {rhs_snip}"); diag.span_suggestion(e.span, "try", sugg, Applicability::MachineApplicable); } }, diff --git a/clippy_lints/src/operators/ptr_eq.rs b/clippy_lints/src/operators/ptr_eq.rs index 1aefc2741c2..1229c202f5a 100644 --- a/clippy_lints/src/operators/ptr_eq.rs +++ b/clippy_lints/src/operators/ptr_eq.rs @@ -34,7 +34,7 @@ pub(super) fn check<'tcx>( expr.span, LINT_MSG, "try", - format!("std::ptr::eq({}, {})", left_snip, right_snip), + format!("std::ptr::eq({left_snip}, {right_snip})"), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/operators/self_assignment.rs b/clippy_lints/src/operators/self_assignment.rs index 9d6bec05bf0..7c9d5320a3a 100644 --- a/clippy_lints/src/operators/self_assignment.rs +++ b/clippy_lints/src/operators/self_assignment.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, lhs: &'tcx cx, SELF_ASSIGNMENT, e.span, - &format!("self-assignment of `{}` to `{}`", rhs, lhs), + &format!("self-assignment of `{rhs}` to `{lhs}`"), ); } } diff --git a/clippy_lints/src/operators/verbose_bit_mask.rs b/clippy_lints/src/operators/verbose_bit_mask.rs index ff85fd55429..fbf65e92b32 100644 --- a/clippy_lints/src/operators/verbose_bit_mask.rs +++ b/clippy_lints/src/operators/verbose_bit_mask.rs @@ -35,7 +35,7 @@ pub(super) fn check<'tcx>( diag.span_suggestion( e.span, "try", - format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()), + format!("{sugg}.trailing_zeros() >= {}", n.count_ones()), Applicability::MaybeIncorrect, ); }, diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 0315678bf97..256d2450001 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -163,7 +163,7 @@ fn try_get_option_occurence<'tcx>( return Some(OptionOccurence { option: format_option_in_sugg(cx, cond_expr, as_ref, as_mut), method_sugg: method_sugg.to_string(), - some_expr: format!("|{}{}| {}", capture_mut, capture_name, Sugg::hir_with_macro_callsite(cx, some_body, "..")), + some_expr: format!("|{capture_mut}{capture_name}| {}", Sugg::hir_with_macro_callsite(cx, some_body, "..")), none_expr: format!("{}{}", if method_sugg == "map_or" { "" } else { "|| " }, Sugg::hir_with_macro_callsite(cx, none_body, "..")), }); } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 0960b050c24..152e0c5ec9a 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -209,7 +209,7 @@ impl<'tcx> PassByRefOrValue { cx, TRIVIALLY_COPY_PASS_BY_REF, input.span, - &format!("this argument ({} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", size, self.ref_min_size), + &format!("this argument ({size} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", self.ref_min_size), "consider passing by value instead", value_type, Applicability::Unspecified, @@ -237,7 +237,7 @@ impl<'tcx> PassByRefOrValue { cx, LARGE_TYPES_PASSED_BY_VALUE, input.span, - &format!("this argument ({} byte) is passed by value, but might be more efficient if passed by reference (limit: {} byte)", size, self.value_max_size), + &format!("this argument ({size} byte) is passed by value, but might be more efficient if passed by reference (limit: {} byte)", self.value_max_size), "consider passing by reference instead", format!("&{}", snippet(cx, input.span, "_")), Applicability::MaybeIncorrect, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 41d1baba64f..85e0710eb50 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -463,7 +463,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( diag.span_suggestion( hir_ty.span, "change this to", - format!("&{}{}", mutability.prefix_str(), ty_name), + format!("&{}{ty_name}", mutability.prefix_str()), Applicability::Unspecified, ); } diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index 4dc65da3ea1..b0a5d1a6758 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -60,7 +60,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrOffsetWithCast { None => return, }; - let msg = format!("use of `{}` with a `usize` casted to an `isize`", method); + let msg = format!("use of `{method}` with a `usize` casted to an `isize`"); if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) { span_lint_and_sugg( cx, @@ -124,7 +124,7 @@ fn build_suggestion<'tcx>( ) -> Option { let receiver = snippet_opt(cx, receiver_expr.span)?; let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?; - Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs)) + Some(format!("{receiver}.{}({cast_lhs})", method.suggestion())) } #[derive(Copy, Clone)] diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index f4f1fd336df..d53614722aa 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -97,12 +97,12 @@ fn check_is_none_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: &Ex !matches!(caller.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)); let sugg = if let Some(else_inner) = r#else { if eq_expr_value(cx, caller, peel_blocks(else_inner)) { - format!("Some({}?)", receiver_str) + format!("Some({receiver_str}?)") } else { return; } } else { - format!("{}{}?;", receiver_str, if by_ref { ".as_ref()" } else { "" }) + format!("{receiver_str}{}?;", if by_ref { ".as_ref()" } else { "" }) }; span_lint_and_sugg( @@ -134,8 +134,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability); let requires_semi = matches!(get_parent_node(cx.tcx, expr.hir_id), Some(Node::Stmt(_))); let sugg = format!( - "{}{}?{}", - receiver_str, + "{receiver_str}{}?{}", if by_ref == ByRef::Yes { ".as_ref()" } else { "" }, if requires_semi { ";" } else { "" } ); diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 918d624eec6..c6fbb5e805a 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -243,9 +243,9 @@ fn check_possible_range_contains( cx, MANUAL_RANGE_CONTAINS, span, - &format!("manual `{}::contains` implementation", range_type), + &format!("manual `{range_type}::contains` implementation"), "use", - format!("({}{}{}{}).contains(&{})", lo, space, range_op, hi, name), + format!("({lo}{space}{range_op}{hi}).contains(&{name})"), applicability, ); } else if !combine_and && ord == Some(l.ord) { @@ -273,9 +273,9 @@ fn check_possible_range_contains( cx, MANUAL_RANGE_CONTAINS, span, - &format!("manual `!{}::contains` implementation", range_type), + &format!("manual `!{range_type}::contains` implementation"), "use", - format!("!({}{}{}{}).contains(&{})", lo, space, range_op, hi, name), + format!("!({lo}{space}{range_op}{hi}).contains(&{name})"), applicability, ); } @@ -372,14 +372,14 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { diag.span_suggestion( span, "use", - format!("({}..={})", start, end), + format!("({start}..={end})"), Applicability::MaybeIncorrect, ); } else { diag.span_suggestion( span, "use", - format!("{}..={}", start, end), + format!("{start}..={end}"), Applicability::MachineApplicable, // snippet ); } @@ -408,7 +408,7 @@ fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { diag.span_suggestion( expr.span, "use", - format!("{}..{}", start, end), + format!("{start}..{end}"), Applicability::MachineApplicable, // snippet ); }, @@ -486,7 +486,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { expr.span, "consider using the following if you are attempting to iterate over this \ range in reverse", - format!("({}{}{}).rev()", end_snippet, dots, start_snippet), + format!("({end_snippet}{dots}{start_snippet}).rev()"), Applicability::MaybeIncorrect, ); } diff --git a/clippy_lints/src/read_zero_byte_vec.rs b/clippy_lints/src/read_zero_byte_vec.rs index 94dec191103..ae80b6f1269 100644 --- a/clippy_lints/src/read_zero_byte_vec.rs +++ b/clippy_lints/src/read_zero_byte_vec.rs @@ -101,9 +101,8 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec { next_stmt_span, "reading zero byte data to `Vec`", "try", - format!("{}.resize({}, 0); {}", + format!("{}.resize({len}, 0); {}", ident.as_str(), - len, snippet(cx, next_stmt_span, "..") ), applicability, diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 323326381d4..9c71a3daeee 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { cx, REDUNDANT_PUB_CRATE, span, - &format!("pub(crate) {} inside private module", descr), + &format!("pub(crate) {descr} inside private module"), |diag| { diag.span_suggestion( item.vis_span, diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 8693ca9af83..245a02ea26e 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -127,9 +127,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; let sugg = if (deref_count != 0 || !reborrow_str.is_empty()) && needs_parens_for_prefix { - format!("({}{}{})", reborrow_str, "*".repeat(deref_count), snip) + format!("({reborrow_str}{}{snip})", "*".repeat(deref_count)) } else { - format!("{}{}{}", reborrow_str, "*".repeat(deref_count), snip) + format!("{reborrow_str}{}{snip}", "*".repeat(deref_count)) }; (lint, help_str, sugg) @@ -141,9 +141,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { if deref_ty == expr_ty { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; let sugg = if needs_parens_for_prefix { - format!("(&{}{}*{})", mutability.prefix_str(), "*".repeat(indexed_ref_count), snip) + format!("(&{}{}*{snip})", mutability.prefix_str(), "*".repeat(indexed_ref_count)) } else { - format!("&{}{}*{}", mutability.prefix_str(), "*".repeat(indexed_ref_count), snip) + format!("&{}{}*{snip}", mutability.prefix_str(), "*".repeat(indexed_ref_count)) }; (DEREF_BY_SLICING_LINT, "dereference the original value instead", sugg) } else { diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 2d751c27467..60ba62c4a43 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -67,7 +67,7 @@ impl RedundantStaticLifetimes { TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => { if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime { let snip = snippet(cx, borrow_type.ty.span, ""); - let sugg = format!("&{}", snip); + let sugg = format!("&{snip}"); span_lint_and_then( cx, REDUNDANT_STATIC_LIFETIMES, diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 6bcae0da8f4..1fda58fa54d 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -172,7 +172,7 @@ fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { ); }, Err(e) => { - span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {}", e)); + span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {e}")); }, } } @@ -200,7 +200,7 @@ fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { ); }, Err(e) => { - span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {}", e)); + span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {e}")); }, } } diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 73f8e083b29..dead36e3bea 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { |diag| { diag.span_note( trait_method_span, - &format!("existing `{}` defined here", method_name), + &format!("existing `{method_name}` defined here"), ); }, ); @@ -151,7 +151,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { // iterate on trait_spans? diag.span_note( trait_spans[0], - &format!("existing `{}` defined here", method_name), + &format!("existing `{method_name}` defined here"), ); }, ); diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index 729694da46d..66638eed998 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for SemicolonIfNothingReturned { } let sugg = sugg::Sugg::hir_with_macro_callsite(cx, expr, ".."); - let suggestion = format!("{0};", sugg); + let suggestion = format!("{sugg};"); span_lint_and_sugg( cx, SEMICOLON_IF_NOTHING_RETURNED, diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index c07aa00a127..e57ab8cd7a3 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -174,7 +174,7 @@ impl SlowVectorInit { diag.span_suggestion( vec_alloc.allocation_expr.span, "consider replace allocation with", - format!("vec![0; {}]", len_expr), + format!("vec![0; {len_expr}]"), Applicability::Unspecified, ); }); diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 662d399ca53..d356c99c8fc 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -284,7 +284,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { e.span, "calling a slice of `as_bytes()` with `from_utf8` should be not necessary", "try", - format!("Some(&{}[{}])", snippet_app, snippet(cx, right.span, "..")), + format!("Some(&{snippet_app}[{}])", snippet(cx, right.span, "..")), applicability ) } @@ -500,8 +500,8 @@ impl<'tcx> LateLintPass<'tcx> for TrimSplitWhitespace { cx, TRIM_SPLIT_WHITESPACE, trim_span.with_hi(split_ws_span.lo()), - &format!("found call to `str::{}` before `str::split_whitespace`", trim_fn_name), - &format!("remove `{}()`", trim_fn_name), + &format!("found call to `str::{trim_fn_name}` before `str::split_whitespace`"), + &format!("remove `{trim_fn_name}()`"), String::new(), Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index 78403d9fdb7..03324c66e8e 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -79,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings { span, "using `libc::strlen` on a `CString` or `CStr` value", "try this", - format!("{}.{}().len()", val_name, method_name), + format!("{val_name}.{method_name}().len()"), app, ); } diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 5d36f0f5ff8..eef9bdc7849 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -326,8 +326,7 @@ fn replace_left_sugg( applicability: &mut Applicability, ) -> String { format!( - "{} {} {}", - left_suggestion, + "{left_suggestion} {} {}", binop.op.to_string(), snippet_with_applicability(cx, binop.right.span, "..", applicability), ) @@ -340,10 +339,9 @@ fn replace_right_sugg( applicability: &mut Applicability, ) -> String { format!( - "{} {} {}", + "{} {} {right_suggestion}", snippet_with_applicability(cx, binop.left.span, "..", applicability), binop.op.to_string(), - right_suggestion, ) } @@ -676,9 +674,8 @@ fn suggestion_with_swapped_ident( } Some(format!( - "{}{}{}", + "{}{new_ident}{}", snippet_with_applicability(cx, expr.span.with_hi(current_ident.span.lo()), "..", applicability), - new_ident, snippet_with_applicability(cx, expr.span.with_lo(current_ident.span.hi()), "..", applicability), )) }) diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 1885f3ca414..f46c21e1265 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -96,7 +96,7 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa cx, MANUAL_SWAP, span, - &format!("this looks like you are swapping elements of `{}` manually", slice), + &format!("this looks like you are swapping elements of `{slice}` manually"), "try", format!( "{}.swap({}, {})", @@ -121,16 +121,16 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa cx, MANUAL_SWAP, span, - &format!("this looks like you are swapping `{}` and `{}` manually", first, second), + &format!("this looks like you are swapping `{first}` and `{second}` manually"), |diag| { diag.span_suggestion( span, "try", - format!("{}::mem::swap({}, {})", sugg, first.mut_addr(), second.mut_addr()), + format!("{sugg}::mem::swap({}, {})", first.mut_addr(), second.mut_addr()), applicability, ); if !is_xor_based { - diag.note(&format!("or maybe you should use `{}::mem::replace`?", sugg)); + diag.note(&format!("or maybe you should use `{sugg}::mem::replace`?")); } }, ); @@ -182,7 +182,7 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) { let rhs0 = Sugg::hir_opt(cx, rhs0); let (what, lhs, rhs) = if let (Some(first), Some(second)) = (lhs0, rhs0) { ( - format!(" `{}` and `{}`", first, second), + format!(" `{first}` and `{second}`"), first.mut_addr().to_string(), second.mut_addr().to_string(), ) @@ -196,22 +196,19 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) { span_lint_and_then(cx, ALMOST_SWAPPED, span, - &format!("this looks like you are trying to swap{}", what), + &format!("this looks like you are trying to swap{what}"), |diag| { if !what.is_empty() { diag.span_suggestion( span, "try", format!( - "{}::mem::swap({}, {})", - sugg, - lhs, - rhs, + "{sugg}::mem::swap({lhs}, {rhs})", ), Applicability::MaybeIncorrect, ); diag.note( - &format!("or maybe you should use `{}::mem::replace`?", sugg) + &format!("or maybe you should use `{sugg}::mem::replace`?") ); } }); diff --git a/clippy_lints/src/swap_ptr_to_ref.rs b/clippy_lints/src/swap_ptr_to_ref.rs index 3cbbda80f3a..d085dda3582 100644 --- a/clippy_lints/src/swap_ptr_to_ref.rs +++ b/clippy_lints/src/swap_ptr_to_ref.rs @@ -58,7 +58,7 @@ impl LateLintPass<'_> for SwapPtrToRef { let mut app = Applicability::MachineApplicable; let snip1 = snippet_with_context(cx, arg1_span.unwrap_or(arg1.span), ctxt, "..", &mut app).0; let snip2 = snippet_with_context(cx, arg2_span.unwrap_or(arg2.span), ctxt, "..", &mut app).0; - diag.span_suggestion(e.span, "use ptr::swap", format!("core::ptr::swap({}, {})", snip1, snip2), app); + diag.span_suggestion(e.span, "use ptr::swap", format!("core::ptr::swap({snip1}, {snip2})"), app); } } ); diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 651201f34ed..2512500a6be 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -84,9 +84,9 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { "use of `.to_digit(..).is_some()`", "try this", if is_method_call { - format!("{}.is_digit({})", char_arg_snip, radix_snip) + format!("{char_arg_snip}.is_digit({radix_snip})") } else { - format!("char::is_digit({}, {})", char_arg_snip, radix_snip) + format!("char::is_digit({char_arg_snip}, {radix_snip})") }, applicability, ); diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index a25be93b8d6..bb146441f87 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -215,9 +215,8 @@ impl TraitBounds { .map(|(_, _, span)| snippet_with_applicability(cx, span, "..", &mut applicability)) .join(" + "); let hint_string = format!( - "consider combining the bounds: `{}: {}`", + "consider combining the bounds: `{}: {trait_bounds}`", snippet(cx, p.bounded_ty.span, "_"), - trait_bounds, ); span_lint_and_help( cx, diff --git a/clippy_lints/src/transmute/crosspointer_transmute.rs b/clippy_lints/src/transmute/crosspointer_transmute.rs index 25d0543c861..c4b9d82fc73 100644 --- a/clippy_lints/src/transmute/crosspointer_transmute.rs +++ b/clippy_lints/src/transmute/crosspointer_transmute.rs @@ -13,10 +13,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty cx, CROSSPOINTER_TRANSMUTE, e.span, - &format!( - "transmute from a type (`{}`) to the type that it points to (`{}`)", - from_ty, to_ty - ), + &format!("transmute from a type (`{from_ty}`) to the type that it points to (`{to_ty}`)"), ); true }, @@ -25,10 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty cx, CROSSPOINTER_TRANSMUTE, e.span, - &format!( - "transmute from a type (`{}`) to a pointer to that type (`{}`)", - from_ty, to_ty - ), + &format!("transmute from a type (`{from_ty}`) to a pointer to that type (`{to_ty}`)"), ); true }, diff --git a/clippy_lints/src/transmute/transmute_float_to_int.rs b/clippy_lints/src/transmute/transmute_float_to_int.rs index 1bde977cfa2..5ecba512b0f 100644 --- a/clippy_lints/src/transmute/transmute_float_to_int.rs +++ b/clippy_lints/src/transmute/transmute_float_to_int.rs @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_FLOAT_TO_INT, e.span, - &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), + &format!("transmute from a `{from_ty}` to a `{to_ty}`"), |diag| { let mut sugg = sugg::Sugg::hir(cx, arg, ".."); @@ -38,7 +38,7 @@ pub(super) fn check<'tcx>( if let ExprKind::Lit(lit) = &arg.kind; if let ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) = lit.node; then { - let op = format!("{}{}", sugg, float_ty.name_str()).into(); + let op = format!("{sugg}{}", float_ty.name_str()).into(); match sugg { sugg::Sugg::MaybeParen(_) => sugg = sugg::Sugg::MaybeParen(op), _ => sugg = sugg::Sugg::NonParen(op) diff --git a/clippy_lints/src/transmute/transmute_int_to_bool.rs b/clippy_lints/src/transmute/transmute_int_to_bool.rs index 8c50b58ca4b..58227c53de2 100644 --- a/clippy_lints/src/transmute/transmute_int_to_bool.rs +++ b/clippy_lints/src/transmute/transmute_int_to_bool.rs @@ -23,7 +23,7 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_INT_TO_BOOL, e.span, - &format!("transmute from a `{}` to a `bool`", from_ty), + &format!("transmute from a `{from_ty}` to a `bool`"), |diag| { let arg = sugg::Sugg::hir(cx, arg, ".."); let zero = sugg::Sugg::NonParen(Cow::from("0")); diff --git a/clippy_lints/src/transmute/transmute_int_to_char.rs b/clippy_lints/src/transmute/transmute_int_to_char.rs index 9e1823c373b..7d31c375f8c 100644 --- a/clippy_lints/src/transmute/transmute_int_to_char.rs +++ b/clippy_lints/src/transmute/transmute_int_to_char.rs @@ -23,7 +23,7 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_INT_TO_CHAR, e.span, - &format!("transmute from a `{}` to a `char`", from_ty), + &format!("transmute from a `{from_ty}` to a `char`"), |diag| { let arg = sugg::Sugg::hir(cx, arg, ".."); let arg = if let ty::Int(_) = from_ty.kind() { @@ -34,7 +34,7 @@ pub(super) fn check<'tcx>( diag.span_suggestion( e.span, "consider using", - format!("std::char::from_u32({}).unwrap()", arg), + format!("std::char::from_u32({arg}).unwrap()"), Applicability::Unspecified, ); }, diff --git a/clippy_lints/src/transmute/transmute_int_to_float.rs b/clippy_lints/src/transmute/transmute_int_to_float.rs index b8703052e6c..cc3422edbbf 100644 --- a/clippy_lints/src/transmute/transmute_int_to_float.rs +++ b/clippy_lints/src/transmute/transmute_int_to_float.rs @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_INT_TO_FLOAT, e.span, - &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), + &format!("transmute from a `{from_ty}` to a `{to_ty}`"), |diag| { let arg = sugg::Sugg::hir(cx, arg, ".."); let arg = if let ty::Int(int_ty) = from_ty.kind() { @@ -36,7 +36,7 @@ pub(super) fn check<'tcx>( diag.span_suggestion( e.span, "consider using", - format!("{}::from_bits({})", to_ty, arg), + format!("{to_ty}::from_bits({arg})"), Applicability::Unspecified, ); }, diff --git a/clippy_lints/src/transmute/transmute_num_to_bytes.rs b/clippy_lints/src/transmute/transmute_num_to_bytes.rs index 52d193d11e1..009d5a7c8ae 100644 --- a/clippy_lints/src/transmute/transmute_num_to_bytes.rs +++ b/clippy_lints/src/transmute/transmute_num_to_bytes.rs @@ -31,13 +31,13 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_NUM_TO_BYTES, e.span, - &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), + &format!("transmute from a `{from_ty}` to a `{to_ty}`"), |diag| { let arg = sugg::Sugg::hir(cx, arg, ".."); diag.span_suggestion( e.span, "consider using `to_ne_bytes()`", - format!("{}.to_ne_bytes()", arg), + format!("{arg}.to_ne_bytes()"), Applicability::Unspecified, ); }, diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index 5eb03275b8e..12d0b866e1c 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -25,10 +25,7 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_PTR_TO_REF, e.span, - &format!( - "transmute from a pointer type (`{}`) to a reference type (`{}`)", - from_ty, to_ty - ), + &format!("transmute from a pointer type (`{from_ty}`) to a reference type (`{to_ty}`)"), |diag| { let arg = sugg::Sugg::hir(cx, arg, ".."); let (deref, cast) = if *mutbl == Mutability::Mut { @@ -41,26 +38,25 @@ pub(super) fn check<'tcx>( let sugg = if let Some(ty) = get_explicit_type(path) { let ty_snip = snippet_with_applicability(cx, ty.span, "..", &mut app); if meets_msrv(msrv, msrvs::POINTER_CAST) { - format!("{}{}.cast::<{}>()", deref, arg.maybe_par(), ty_snip) + format!("{deref}{}.cast::<{ty_snip}>()", arg.maybe_par()) } else if from_ptr_ty.has_erased_regions() { - sugg::make_unop(deref, arg.as_ty(format!("{} () as {} {}", cast, cast, ty_snip))) - .to_string() + sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {ty_snip}"))).to_string() } else { - sugg::make_unop(deref, arg.as_ty(format!("{} {}", cast, ty_snip))).to_string() + sugg::make_unop(deref, arg.as_ty(format!("{cast} {ty_snip}"))).to_string() } } else if from_ptr_ty.ty == *to_ref_ty { if from_ptr_ty.has_erased_regions() { if meets_msrv(msrv, msrvs::POINTER_CAST) { - format!("{}{}.cast::<{}>()", deref, arg.maybe_par(), to_ref_ty) + format!("{deref}{}.cast::<{to_ref_ty}>()", arg.maybe_par()) } else { - sugg::make_unop(deref, arg.as_ty(format!("{} () as {} {}", cast, cast, to_ref_ty))) + sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {to_ref_ty}"))) .to_string() } } else { sugg::make_unop(deref, arg).to_string() } } else { - sugg::make_unop(deref, arg.as_ty(format!("{} {}", cast, to_ref_ty))).to_string() + sugg::make_unop(deref, arg.as_ty(format!("{cast} {to_ref_ty}"))).to_string() }; diag.span_suggestion(e.span, "try", sugg, app); diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index 707a11d361c..afb7f2e1326 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -38,7 +38,7 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_BYTES_TO_STR, e.span, - &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), + &format!("transmute from a `{from_ty}` to a `{to_ty}`"), "consider using", if const_context { format!("std::str::from_utf8_unchecked{postfix}({snippet})") diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index b6d7d9f5b42..cac620cf8e8 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -75,10 +75,10 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_UNDEFINED_REPR, e.span, - &format!("transmute from `{}` which has an undefined layout", from_ty_orig), + &format!("transmute from `{from_ty_orig}` which has an undefined layout"), |diag| { if from_ty_orig.peel_refs() != from_ty.peel_refs() { - diag.note(&format!("the contained type `{}` has an undefined layout", from_ty)); + diag.note(&format!("the contained type `{from_ty}` has an undefined layout")); } }, ); @@ -89,10 +89,10 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_UNDEFINED_REPR, e.span, - &format!("transmute to `{}` which has an undefined layout", to_ty_orig), + &format!("transmute to `{to_ty_orig}` which has an undefined layout"), |diag| { if to_ty_orig.peel_refs() != to_ty.peel_refs() { - diag.note(&format!("the contained type `{}` has an undefined layout", to_ty)); + diag.note(&format!("the contained type `{to_ty}` has an undefined layout")); } }, ); @@ -116,8 +116,7 @@ pub(super) fn check<'tcx>( TRANSMUTE_UNDEFINED_REPR, e.span, &format!( - "transmute from `{}` to `{}`, both of which have an undefined layout", - from_ty_orig, to_ty_orig + "transmute from `{from_ty_orig}` to `{to_ty_orig}`, both of which have an undefined layout" ), |diag| { if let Some(same_adt_did) = same_adt_did { @@ -127,10 +126,10 @@ pub(super) fn check<'tcx>( )); } else { if from_ty_orig.peel_refs() != from_ty { - diag.note(&format!("the contained type `{}` has an undefined layout", from_ty)); + diag.note(&format!("the contained type `{from_ty}` has an undefined layout")); } if to_ty_orig.peel_refs() != to_ty { - diag.note(&format!("the contained type `{}` has an undefined layout", to_ty)); + diag.note(&format!("the contained type `{to_ty}` has an undefined layout")); } } }, @@ -145,10 +144,10 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_UNDEFINED_REPR, e.span, - &format!("transmute from `{}` which has an undefined layout", from_ty_orig), + &format!("transmute from `{from_ty_orig}` which has an undefined layout"), |diag| { if from_ty_orig.peel_refs() != from_ty { - diag.note(&format!("the contained type `{}` has an undefined layout", from_ty)); + diag.note(&format!("the contained type `{from_ty}` has an undefined layout")); } }, ); @@ -162,10 +161,10 @@ pub(super) fn check<'tcx>( cx, TRANSMUTE_UNDEFINED_REPR, e.span, - &format!("transmute into `{}` which has an undefined layout", to_ty_orig), + &format!("transmute into `{to_ty_orig}` which has an undefined layout"), |diag| { if to_ty_orig.peel_refs() != to_ty { - diag.note(&format!("the contained type `{}` has an undefined layout", to_ty)); + diag.note(&format!("the contained type `{to_ty}` has an undefined layout")); } }, ); diff --git a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs index 626d7cd46fc..6b444922a7c 100644 --- a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs +++ b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs @@ -21,10 +21,7 @@ pub(super) fn check<'tcx>( cx, TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, e.span, - &format!( - "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", - from_ty, to_ty - ), + &format!("transmute from `{from_ty}` to `{to_ty}` which could be expressed as a pointer cast instead"), |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { let sugg = arg.as_ty(&to_ty.to_string()).to_string(); diff --git a/clippy_lints/src/transmute/unsound_collection_transmute.rs b/clippy_lints/src/transmute/unsound_collection_transmute.rs index 831b0d450d2..b1445311b71 100644 --- a/clippy_lints/src/transmute/unsound_collection_transmute.rs +++ b/clippy_lints/src/transmute/unsound_collection_transmute.rs @@ -37,10 +37,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty cx, UNSOUND_COLLECTION_TRANSMUTE, e.span, - &format!( - "transmute from `{}` to `{}` with mismatched layout is unsound", - from_ty, to_ty - ), + &format!("transmute from `{from_ty}` to `{to_ty}` with mismatched layout is unsound"), ); true } else { diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 8122cd716e0..f919bbd5afc 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>( cx, USELESS_TRANSMUTE, e.span, - &format!("transmute from a type (`{}`) to itself", from_ty), + &format!("transmute from a type (`{from_ty}`) to itself"), ); true }, diff --git a/clippy_lints/src/transmute/wrong_transmute.rs b/clippy_lints/src/transmute/wrong_transmute.rs index 2118f3d6950..d1965565b92 100644 --- a/clippy_lints/src/transmute/wrong_transmute.rs +++ b/clippy_lints/src/transmute/wrong_transmute.rs @@ -13,7 +13,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty cx, WRONG_TRANSMUTE, e.span, - &format!("transmute from a `{}` to a pointer", from_ty), + &format!("transmute from a `{from_ty}` to a pointer"), ); true }, diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 94945b2e1a9..0a779b37860 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -49,15 +49,15 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m let inner_snippet = snippet(cx, inner.span, ".."); let suggestion = match &inner.kind { TyKind::TraitObject(bounds, lt_bound, _) if bounds.len() > 1 || !lt_bound.is_elided() => { - format!("&{}({})", ltopt, &inner_snippet) + format!("&{ltopt}({})", &inner_snippet) }, TyKind::Path(qpath) if get_bounds_if_impl_trait(cx, qpath, inner.hir_id) .map_or(false, |bounds| bounds.len() > 1) => { - format!("&{}({})", ltopt, &inner_snippet) + format!("&{ltopt}({})", &inner_snippet) }, - _ => format!("&{}{}", ltopt, &inner_snippet), + _ => format!("&{ltopt}{}", &inner_snippet), }; span_lint_and_sugg( cx, diff --git a/clippy_lints/src/types/box_collection.rs b/clippy_lints/src/types/box_collection.rs index ba51404d214..08020ce6638 100644 --- a/clippy_lints/src/types/box_collection.rs +++ b/clippy_lints/src/types/box_collection.rs @@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ _ => "<..>", }; - let box_content = format!("{outer}{generic}", outer = item_type); + let box_content = format!("{item_type}{generic}"); span_lint_and_help( cx, BOX_COLLECTION, diff --git a/clippy_lints/src/types/rc_buffer.rs b/clippy_lints/src/types/rc_buffer.rs index 4d72a29e8c7..6b9de64e24c 100644 --- a/clippy_lints/src/types/rc_buffer.rs +++ b/clippy_lints/src/types/rc_buffer.rs @@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ hir_ty.span, "usage of `Rc` when T is a buffer type", "try", - format!("Rc<{}>", alternate), + format!("Rc<{alternate}>"), Applicability::MachineApplicable, ); } else { @@ -57,7 +57,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ hir_ty.span, "usage of `Arc` when T is a buffer type", "try", - format!("Arc<{}>", alternate), + format!("Arc<{alternate}>"), Applicability::MachineApplicable, ); } else if let Some(ty) = qpath_generic_tys(qpath).next() { diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index a1312fcda0b..b95f0213e0c 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -27,13 +27,11 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ cx, REDUNDANT_ALLOCATION, hir_ty.span, - &format!("usage of `{}<{}>`", outer_sym, generic_snippet), + &format!("usage of `{outer_sym}<{generic_snippet}>`"), |diag| { - diag.span_suggestion(hir_ty.span, "try", format!("{}", generic_snippet), applicability); + diag.span_suggestion(hir_ty.span, "try", format!("{generic_snippet}"), applicability); diag.note(&format!( - "`{generic}` is already a pointer, `{outer}<{generic}>` allocates a pointer on the heap", - outer = outer_sym, - generic = generic_snippet + "`{generic_snippet}` is already a pointer, `{outer_sym}<{generic_snippet}>` allocates a pointer on the heap" )); }, ); @@ -72,19 +70,16 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ cx, REDUNDANT_ALLOCATION, hir_ty.span, - &format!("usage of `{}<{}<{}>>`", outer_sym, inner_sym, generic_snippet), + &format!("usage of `{outer_sym}<{inner_sym}<{generic_snippet}>>`"), |diag| { diag.span_suggestion( hir_ty.span, "try", - format!("{}<{}>", outer_sym, generic_snippet), + format!("{outer_sym}<{generic_snippet}>"), applicability, ); diag.note(&format!( - "`{inner}<{generic}>` is already on the heap, `{outer}<{inner}<{generic}>>` makes an extra allocation", - outer = outer_sym, - inner = inner_sym, - generic = generic_snippet + "`{inner_sym}<{generic_snippet}>` is already on the heap, `{outer_sym}<{inner_sym}<{generic_snippet}>>` makes an extra allocation" )); }, ); @@ -94,19 +89,13 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ cx, REDUNDANT_ALLOCATION, hir_ty.span, - &format!("usage of `{}<{}<{}>>`", outer_sym, inner_sym, generic_snippet), + &format!("usage of `{outer_sym}<{inner_sym}<{generic_snippet}>>`"), |diag| { diag.note(&format!( - "`{inner}<{generic}>` is already on the heap, `{outer}<{inner}<{generic}>>` makes an extra allocation", - outer = outer_sym, - inner = inner_sym, - generic = generic_snippet + "`{inner_sym}<{generic_snippet}>` is already on the heap, `{outer_sym}<{inner_sym}<{generic_snippet}>>` makes an extra allocation" )); diag.help(&format!( - "consider using just `{outer}<{generic}>` or `{inner}<{generic}>`", - outer = outer_sym, - inner = inner_sym, - generic = generic_snippet + "consider using just `{outer_sym}<{generic_snippet}>` or `{inner_sym}<{generic_snippet}>`" )); }, ); diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index c0a4f3fbacd..57aff5367dd 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -157,8 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd { span, &format!( "this closure returns \ - the unit type which also implements {}", - trait_name + the unit type which also implements {trait_name}" ), ); }, @@ -169,8 +168,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd { span, &format!( "this closure returns \ - the unit type which also implements {}", - trait_name + the unit type which also implements {trait_name}" ), Some(last_semi), "probably caused by this trailing semicolon", diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index a6f777abc6e..f6d3fb00f4e 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -74,7 +74,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp cx, UNIT_ARG, expr.span, - &format!("passing {}unit value{} to a function", singular, plural), + &format!("passing {singular}unit value{plural} to a function"), |db| { let mut or = ""; args_to_recover @@ -129,7 +129,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp if arg_snippets_without_empty_blocks.is_empty() { db.multipart_suggestion( - &format!("use {}unit literal{} instead", singular, plural), + &format!("use {singular}unit literal{plural} instead"), args_to_recover .iter() .map(|arg| (arg.span, "()".to_string())) @@ -143,8 +143,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp db.span_suggestion( expr.span, &format!( - "{}move the expression{} in front of the call and replace {} with the unit literal `()`", - or, empty_or_s, it_or_them + "{or}move the expression{empty_or_s} in front of the call and replace {it_or_them} with the unit literal `()`" ), sugg, applicability, diff --git a/clippy_lints/src/unit_types/unit_cmp.rs b/clippy_lints/src/unit_types/unit_cmp.rs index 1dd8895ebd0..226495dcbda 100644 --- a/clippy_lints/src/unit_types/unit_cmp.rs +++ b/clippy_lints/src/unit_types/unit_cmp.rs @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { cx, UNIT_CMP, macro_call.span, - &format!("`{}` of unit values detected. This will always {}", macro_name, result), + &format!("`{macro_name}` of unit values detected. This will always {result}"), ); } return; @@ -40,9 +40,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { UNIT_CMP, expr.span, &format!( - "{}-comparison of unit values detected. This will always be {}", - op.as_str(), - result + "{}-comparison of unit values detected. This will always be {result}", + op.as_str() ), ); } diff --git a/clippy_lints/src/unnecessary_self_imports.rs b/clippy_lints/src/unnecessary_self_imports.rs index 839a4bdab09..bc0dd263d88 100644 --- a/clippy_lints/src/unnecessary_self_imports.rs +++ b/clippy_lints/src/unnecessary_self_imports.rs @@ -57,7 +57,7 @@ impl EarlyLintPass for UnnecessarySelfImports { format!( "{}{};", last_segment.ident, - if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {}", alias) } else { String::new() }, + if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {alias}") } else { String::new() }, ), Applicability::MaybeIncorrect, ); diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 2c40827db0e..83ef3b0fac8 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -153,11 +153,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { ) } else { ( - format!( - "this function's return value is unnecessarily wrapped by `{}`", - return_type_label - ), - format!("remove `{}` from the return type...", return_type_label), + format!("this function's return value is unnecessarily wrapped by `{return_type_label}`"), + format!("remove `{return_type_label}` from the return type..."), inner_type.to_string(), "...and then change returning expressions", ) diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 64f7a055cd9..32cd4681201 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -65,10 +65,7 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>, cx, UNSAFE_REMOVED_FROM_NAME, span, - &format!( - "removed `unsafe` from the name of `{}` in use as `{}`", - old_str, new_str - ), + &format!("removed `unsafe` from the name of `{old_str}` in use as `{new_str}`"), ); } } diff --git a/clippy_lints/src/unused_rounding.rs b/clippy_lints/src/unused_rounding.rs index b8a5d4ea8c9..3164937293b 100644 --- a/clippy_lints/src/unused_rounding.rs +++ b/clippy_lints/src/unused_rounding.rs @@ -58,8 +58,8 @@ impl EarlyLintPass for UnusedRounding { cx, UNUSED_ROUNDING, expr.span, - &format!("used the `{}` method with a whole number float", method_name), - &format!("remove the `{}` method call", method_name), + &format!("used the `{method_name}` method with a whole number float"), + &format!("remove the `{method_name}` method call"), float, Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 7e451b7b7a4..45e2f550236 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -257,9 +257,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { expr.hir_id, expr.span, &format!( - "called `{}` on `{}` after checking its variant with `{}`", + "called `{}` on `{unwrappable_variable_name}` after checking its variant with `{}`", method_name.ident.name, - unwrappable_variable_name, unwrappable.check_name.ident.as_str(), ), |diag| { @@ -268,9 +267,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { unwrappable.check.span.with_lo(unwrappable.if_expr.span.lo()), "try", format!( - "if let {} = {}", - suggested_pattern, - unwrappable_variable_name, + "if let {suggested_pattern} = {unwrappable_variable_name}", ), // We don't track how the unwrapped value is used inside the // block or suggest deleting the unwrap, so we can't offer a diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 02bf09ed506..378cc427f5a 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -93,7 +93,7 @@ fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) { cx, UPPER_CASE_ACRONYMS, span, - &format!("name `{}` contains a capitalized acronym", ident), + &format!("name `{ident}` contains a capitalized acronym"), "consider making the acronym lowercase, except the initial letter", corrected, Applicability::MaybeIncorrect, diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index f1b6463ad0f..50c5a832430 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { cx, USELESS_CONVERSION, e.span, - &format!("useless conversion to the same type: `{}`", b), + &format!("useless conversion to the same type: `{b}`"), "consider removing `.into()`", sugg, Applicability::MachineApplicable, // snippet @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { cx, USELESS_CONVERSION, e.span, - &format!("useless conversion to the same type: `{}`", b), + &format!("useless conversion to the same type: `{b}`"), "consider removing `.into_iter()`", sugg, Applicability::MachineApplicable, // snippet @@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { cx, USELESS_CONVERSION, e.span, - &format!("useless conversion to the same type: `{}`", b), + &format!("useless conversion to the same type: `{b}`"), None, "consider removing `.try_into()`", ); @@ -146,7 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { cx, USELESS_CONVERSION, e.span, - &format!("useless conversion to the same type: `{}`", b), + &format!("useless conversion to the same type: `{b}`"), None, &hint, ); @@ -165,7 +165,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { cx, USELESS_CONVERSION, e.span, - &format!("useless conversion to the same type: `{}`", b), + &format!("useless conversion to the same type: `{b}`"), &sugg_msg, sugg.to_string(), Applicability::MachineApplicable, // snippet diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 4003fff27c0..65576b7203f 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -739,7 +739,7 @@ fn path_to_string(path: &QPath<'_>) -> String { *s += ", "; write!(s, "{:?}", segment.ident.as_str()).unwrap(); }, - other => write!(s, "/* unimplemented: {:?}*/", other).unwrap(), + other => write!(s, "/* unimplemented: {other:?}*/").unwrap(), }, QPath::LangItem(..) => panic!("path_to_string: called for lang item qpath"), } diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 2be3fa99c81..6f5a638be12 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -482,16 +482,13 @@ pub fn format_error(error: Box) -> String { let field = fields.get(index).copied().unwrap_or_default(); write!( msg, - "{:separator_width$}{:field_width$}", - " ", - field, - separator_width = SEPARATOR_WIDTH, - field_width = column_width + "{:SEPARATOR_WIDTH$}{field:column_width$}", + " " ) .unwrap(); } } - write!(msg, "\n{}", suffix).unwrap(); + write!(msg, "\n{suffix}").unwrap(); msg } else { s diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 5418eca382d..33138551011 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -173,7 +173,7 @@ impl LateLintPass<'_> for WildcardImports { let sugg = if braced_glob { imports_string } else { - format!("{}::{}", import_source_snippet, imports_string) + format!("{import_source_snippet}::{imports_string}") }; let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res { diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 50d3c079fe6..9b3de35dbd3 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -57,8 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ZeroDiv { "constant division of `0.0` with `0.0` will always result in NaN", None, &format!( - "consider using `{}::NAN` if you would like a constant representing NaN", - float_type, + "consider using `{float_type}::NAN` if you would like a constant representing NaN", ), ); } -- cgit 1.4.1-3-g733a5