Skip to content

Commit 173a8e0

Browse files
committed
Replace from_different_macros with equivalent and simpler check
1 parent 5da7a17 commit 173a8e0

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

clippy_lints/src/manual_let_else.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_middle::lint::in_external_macro;
1111
use rustc_semver::RustcVersion;
1212
use rustc_session::{declare_tool_lint, impl_lint_pass};
1313
use rustc_span::symbol::sym;
14-
use rustc_span::Span;
1514
use std::ops::ControlFlow;
1615

1716
declare_clippy_lint! {
@@ -66,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
6665
if !in_external_macro(cx.sess(), stmt.span);
6766
if let StmtKind::Local(local) = stmt.kind;
6867
if let Some(init) = local.init;
69-
if !from_different_macros(init.span, stmt.span);
68+
if init.span.ctxt() == stmt.span.ctxt();
7069
if let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init);
7170
then {
7271
if_let_or_match
@@ -179,23 +178,6 @@ fn expr_diverges(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool {
179178
.is_some()
180179
}
181180

182-
/// Returns true if the two spans come from different macro sites,
183-
/// or one comes from an invocation and the other is not from a macro at all.
184-
fn from_different_macros(span_a: Span, span_b: Span) -> bool {
185-
// This pre-check is a speed up so that we don't build outer_expn_data unless needed.
186-
match (span_a.from_expansion(), span_b.from_expansion()) {
187-
(false, false) => return false,
188-
(true, false) | (false, true) => return true,
189-
// We need to determine if both are from the same macro
190-
(true, true) => (),
191-
}
192-
let data_for_comparison = |sp: Span| {
193-
let expn_data = sp.ctxt().outer_expn_data();
194-
(expn_data.kind, expn_data.call_site)
195-
};
196-
data_for_comparison(span_a) != data_for_comparison(span_b)
197-
}
198-
199181
fn pat_allowed_for_else(cx: &LateContext<'_>, pat: &'_ Pat<'_>) -> bool {
200182
// Check whether the pattern contains any bindings, as the
201183
// binding might potentially be used in the body.

0 commit comments

Comments
 (0)