diff --git a/examples/experimental/derive_opportunity/src/lib.rs b/examples/experimental/derive_opportunity/src/lib.rs index 3d540deb5..895d22fb6 100644 --- a/examples/experimental/derive_opportunity/src/lib.rs +++ b/examples/experimental/derive_opportunity/src/lib.rs @@ -336,7 +336,9 @@ fn is_derived(cx: &LateContext<'_>, def_id: DefId) -> Option { // smoelius: I'm not sure whether `SyntaxExtension::builtin_name` would be the right // thing to use here; regardless, I can't figure out how to retrieve that data: // https://github.com/rust-lang/rust/blob/d651fa78cefecefa87fa3d7dc1e1389d275afb63/compiler/rustc_expand/src/base.rs#L729-L731 - Some(Macro::Builtin(*cx.get_def_path(macro_def_id).last().unwrap())) + Some(Macro::Builtin( + *cx.get_def_path(macro_def_id).last().unwrap(), + )) } else { Some(Macro::External(macro_def_id)) } diff --git a/examples/general/incorrect_matches_operation/src/lib.rs b/examples/general/incorrect_matches_operation/src/lib.rs index 6b061c73c..5321fbb19 100644 --- a/examples/general/incorrect_matches_operation/src/lib.rs +++ b/examples/general/incorrect_matches_operation/src/lib.rs @@ -58,8 +58,8 @@ dylint_linting::declare_pre_expansion_lint! { fn is_matches_macro(expr: &P) -> Option<&P> { if_chain! { - if let ExprKind::MacCall(mac) = &expr.kind; // must be a macro call - if mac.path == sym!(matches); // must be a matches! symbol + if let ExprKind::MacCall(mac) = &expr.kind; // must be a macro call + if mac.path == sym!(matches); // must be a matches! symbol then { return Some(mac); } @@ -111,7 +111,10 @@ impl EarlyLintPass for IncorrectMatchesOperation { // Look for binary operators if let ExprKind::Binary(op, left, right) = &expr.kind; // Ensure the binary operator is |, ||, &&, & - if matches!(op.node, BinOpKind::BitOr | BinOpKind::Or | BinOpKind::And | BinOpKind::BitAnd); + if matches!( + op.node, + BinOpKind::BitOr | BinOpKind::Or | BinOpKind::And | BinOpKind::BitAnd + ); // The left side needs to be a matches! macro call if let Some(matches1) = is_matches_macro(left); // The right side needs to be a matches! macro call @@ -133,14 +136,13 @@ impl EarlyLintPass for IncorrectMatchesOperation { } // For & and && operators, this is likely a bug BinOpKind::BitAnd | BinOpKind::And => { - let op = if op.node == BinOpKind::BitAnd { "&" } else { "&&" }; + let op = if op.node == BinOpKind::BitAnd { + "&" + } else { + "&&" + }; let msg = format!("Is this a bug? matches!(obj, A) {op} matches!(obj, B) is (almost) always false"); - span_lint( - cx, - INCORRECT_MATCHES_OPERATION, - expr.span, - &msg, - ); + span_lint(cx, INCORRECT_MATCHES_OPERATION, expr.span, &msg); } _ => { unreachable!("This should never happen - op.node can't be other operator"); diff --git a/examples/general/incorrect_matches_operation/ui/main.rs b/examples/general/incorrect_matches_operation/ui/main.rs index f010ad495..fec1c7866 100644 --- a/examples/general/incorrect_matches_operation/ui/main.rs +++ b/examples/general/incorrect_matches_operation/ui/main.rs @@ -23,4 +23,3 @@ fn main() { // This one will not error out let _c = matches!(x, 2) | matches!(_b, true); } - diff --git a/examples/restriction/collapsible_unwrap/src/lib.rs b/examples/restriction/collapsible_unwrap/src/lib.rs index 1673c223d..c26437749 100644 --- a/examples/restriction/collapsible_unwrap/src/lib.rs +++ b/examples/restriction/collapsible_unwrap/src/lib.rs @@ -83,39 +83,38 @@ impl CollapsibleUnwrap { if let Some((method, mut recv, _, _, span)) = method_call(expr); let snip_span = trim_span(cx.sess().source_map(), span.with_lo(recv.span.hi())); if let Some(snip) = snippet_opt(cx, snip_span); - if let Some((span_sugg, prefix)) = - if method == "and_then" { - Some((&mut and_then_span_sugg, snip)) - } else if let Some((inner_method, inner_recv, _, _, _)) = method_call(recv) - && inner_method == "unwrap" - { - if and_then_span_sugg.is_none() { - and_then_span_sugg = Some(SpanSugg { - span: expr.span.with_lo(expr.span.hi()), - sugg: String::new(), - }); - } - unwrap_span_sugg = and_then_span_sugg.clone(); - let needs_mut = cx - .typeck_results() - .type_dependent_def_id(expr.hir_id) - .map_or(false, |def_id| has_ref_mut_self(cx, def_id)); - let recv_ty = cx.typeck_results().expr_ty(recv); - let name = suggest_name_from_type(cx, recv_ty); - recv = inner_recv; - Some(( - &mut unwrap_span_sugg, - format!( - ".and_then(|{}{}| {}{})", - if needs_mut { "mut "} else { "" }, - name, - name, - snip - ) - )) - } else { - None - }; + if let Some((span_sugg, prefix)) = if method == "and_then" { + Some((&mut and_then_span_sugg, snip)) + } else if let Some((inner_method, inner_recv, _, _, _)) = method_call(recv) + && inner_method == "unwrap" + { + if and_then_span_sugg.is_none() { + and_then_span_sugg = Some(SpanSugg { + span: expr.span.with_lo(expr.span.hi()), + sugg: String::new(), + }); + } + unwrap_span_sugg = and_then_span_sugg.clone(); + let needs_mut = cx + .typeck_results() + .type_dependent_def_id(expr.hir_id) + .map_or(false, |def_id| has_ref_mut_self(cx, def_id)); + let recv_ty = cx.typeck_results().expr_ty(recv); + let name = suggest_name_from_type(cx, recv_ty); + recv = inner_recv; + Some(( + &mut unwrap_span_sugg, + format!( + ".and_then(|{}{}| {}{})", + if needs_mut { "mut " } else { "" }, + name, + name, + snip + ), + )) + } else { + None + }; let expr_ty = cx.typeck_results().expr_ty(expr); let expr_err_ty = result_err_ty(cx, expr_ty); let recv_ty = cx.typeck_results().expr_ty(recv); @@ -154,7 +153,9 @@ impl CollapsibleUnwrap { } } - if let Some(SpanSugg { span, sugg }) = unwrap_span_sugg && !span.is_empty() { + if let Some(SpanSugg { span, sugg }) = unwrap_span_sugg + && !span.is_empty() + { span_lint_and_sugg( cx, COLLAPSIBLE_UNWRAP, diff --git a/examples/restriction/overscoped_allow/src/lib.rs b/examples/restriction/overscoped_allow/src/lib.rs index 84c795eba..29e605894 100644 --- a/examples/restriction/overscoped_allow/src/lib.rs +++ b/examples/restriction/overscoped_allow/src/lib.rs @@ -143,7 +143,9 @@ fn read_diagnostics() -> Result> { let mut diagnostics = Vec::new(); for result in serde_json::Deserializer::from_reader(file).into_iter::() { let message = result?; - if message.reason == "compiler-message" && let Some(diagnostic) = message.message { + if message.reason == "compiler-message" + && let Some(diagnostic) = message.message + { diagnostics.push(diagnostic); } } diff --git a/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs b/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs index df596adf5..1531b8eb4 100644 --- a/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs +++ b/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs @@ -250,7 +250,10 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryConversionForTrait { (false, "inner argument") }; let msg = format!("the {subject} implements the required traits"); - if is_bare_method_call && refs_prefix.is_empty() && !maybe_arg.span.from_expansion() { + if is_bare_method_call + && refs_prefix.is_empty() + && !maybe_arg.span.from_expansion() + { span_lint_and_sugg( cx, UNNECESSARY_CONVERSION_FOR_TRAIT, @@ -260,7 +263,9 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryConversionForTrait { String::new(), Applicability::MachineApplicable, ); - } else if maybe_arg.span.from_expansion() && let Some(span) = maybe_arg.span.parent_callsite() { + } else if maybe_arg.span.from_expansion() + && let Some(span) = maybe_arg.span.parent_callsite() + { // smoelius: This message could be more informative. span_lint_and_help( cx, @@ -610,11 +615,16 @@ fn replace_types<'tcx>( { let projection = cx.tcx.mk_ty_from_kind(ty::Alias( ty::Projection, - projection_predicate.projection_ty.with_self_ty(cx.tcx, new_ty), + projection_predicate + .projection_ty + .with_self_ty(cx.tcx, new_ty), )); - if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection) - && substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty) + if let Ok(projected_ty) = cx + .tcx + .try_normalize_erasing_regions(cx.param_env, projection) + && substs[term_param_ty.index as usize] + != ty::GenericArg::from(projected_ty) { deque.push_back((*term_param_ty, projected_ty)); }