about summary refs log tree commit diff
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2022-10-06 23:07:58 +0200
committerest31 <MTest31@outlook.com>2022-10-24 22:05:39 +0200
commit173a8e04807dbdcc714d7dec0da331ee86538131 (patch)
tree4c7cf84e25b859e2f656310b9499c83ace4a7b24
parent5da7a176b778656d2e6f736f5a23ce6fdb73379d (diff)
downloadrust-173a8e04807dbdcc714d7dec0da331ee86538131.tar.gz
rust-173a8e04807dbdcc714d7dec0da331ee86538131.zip
Replace from_different_macros with equivalent and simpler check
-rw-r--r--clippy_lints/src/manual_let_else.rs20
1 files changed, 1 insertions, 19 deletions
diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs
index 87bac8aabdc..e366d6db774 100644
--- a/clippy_lints/src/manual_let_else.rs
+++ b/clippy_lints/src/manual_let_else.rs
@@ -11,7 +11,6 @@ use rustc_middle::lint::in_external_macro;
 use rustc_semver::RustcVersion;
 use rustc_session::{declare_tool_lint, impl_lint_pass};
 use rustc_span::symbol::sym;
-use rustc_span::Span;
 use std::ops::ControlFlow;
 
 declare_clippy_lint! {
@@ -66,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
             if !in_external_macro(cx.sess(), stmt.span);
             if let StmtKind::Local(local) = stmt.kind;
             if let Some(init) = local.init;
-            if !from_different_macros(init.span, stmt.span);
+            if init.span.ctxt() == stmt.span.ctxt();
             if let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init);
             then {
                 if_let_or_match
@@ -179,23 +178,6 @@ fn expr_diverges(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool {
     .is_some()
 }
 
-/// Returns true if the two spans come from different macro sites,
-/// or one comes from an invocation and the other is not from a macro at all.
-fn from_different_macros(span_a: Span, span_b: Span) -> bool {
-    // This pre-check is a speed up so that we don't build outer_expn_data unless needed.
-    match (span_a.from_expansion(), span_b.from_expansion()) {
-        (false, false) => return false,
-        (true, false) | (false, true) => return true,
-        // We need to determine if both are from the same macro
-        (true, true) => (),
-    }
-    let data_for_comparison = |sp: Span| {
-        let expn_data = sp.ctxt().outer_expn_data();
-        (expn_data.kind, expn_data.call_site)
-    };
-    data_for_comparison(span_a) != data_for_comparison(span_b)
-}
-
 fn pat_allowed_for_else(cx: &LateContext<'_>, pat: &'_ Pat<'_>) -> bool {
     // Check whether the pattern contains any bindings, as the
     // binding might potentially be used in the body.