]> git.proxmox.com Git - rustc.git/blobdiff - src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs
Merge 1.70 into proxmox/bookworm
[rustc.git] / src / tools / clippy / clippy_lints / src / matches / manual_unwrap_or.rs
index 587c926dc01c3f02d790653c72dcbc3d8eded3e8..b94501bf0ad38d4d9f22a785bf4ecf21fd9b336c 100644 (file)
@@ -10,7 +10,6 @@ use rustc_hir::def::{DefKind, Res};
 use rustc_hir::LangItem::{OptionNone, ResultErr};
 use rustc_hir::{Arm, Expr, PatKind};
 use rustc_lint::LateContext;
-use rustc_middle::ty::DefIdTree;
 use rustc_span::sym;
 
 use super::MANUAL_UNWRAP_OR;
@@ -33,14 +32,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, scrutinee:
             let reindented_or_body =
                 reindent_multiline(or_body_snippet.into(), true, Some(indent));
 
-            let suggestion = if scrutinee.span.from_expansion() {
-                    // we don't want parentheses around macro, e.g. `(some_macro!()).unwrap_or(0)`
-                    sugg::Sugg::hir_with_macro_callsite(cx, scrutinee, "..")
-                }
-                else {
-                    sugg::Sugg::hir(cx, scrutinee, "..").maybe_par()
-                };
-
+            let mut app = Applicability::MachineApplicable;
+            let suggestion = sugg::Sugg::hir_with_context(cx, scrutinee, expr.span.ctxt(), "..", &mut app).maybe_par();
             span_lint_and_sugg(
                 cx,
                 MANUAL_UNWRAP_OR, expr.span,
@@ -49,7 +42,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, scrutinee:
                 format!(
                     "{suggestion}.unwrap_or({reindented_or_body})",
                 ),
-                Applicability::MachineApplicable,
+                app,
             );
         }
     }