Skip to content

Commit d1b8d9c

Browse files
committed
Auto merge of rust-lang#119531 - petrochenkov:cmpctxt, r=cjgillot
rustc_span: Optimize syntax context comparisons Including comparisons with root context. - `eq_ctxt` doesn't require retrieving full `SpanData`, or taking the span interner lock twice. - Checking `SyntaxContext` for "rootness" is cheaper than extracting a full outer `ExpnData` for it and checking *it* for rootness. The internal lint for `eq_ctxt` is also tweaked to detect `a.ctxt() != b.ctxt()` in addition to `a.ctxt() == b.ctxt()`.
2 parents 84c4b52 + e10a05d commit d1b8d9c

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

clippy_lints/src/casts/unnecessary_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub(super) fn check<'tcx>(
145145
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
146146
if let Some(id) = path_to_local(cast_expr)
147147
&& let Some(span) = cx.tcx.hir().opt_span(id)
148-
&& span.ctxt() != cast_expr.span.ctxt()
148+
&& !span.eq_ctxt(cast_expr.span)
149149
{
150150
// Binding context is different than the identifiers context.
151151
// Weird macro wizardry could be involved here.

clippy_lints/src/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
118118
vis.visit_ty(impl_.self_ty);
119119

120120
for target in &vis.found {
121-
if item.span.ctxt() != target.span().ctxt() {
121+
if !item.span.eq_ctxt(target.span()) {
122122
return;
123123
}
124124

clippy_lints/src/implicit_return.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
225225
_: LocalDefId,
226226
) {
227227
if (!matches!(kind, FnKind::Closure) && matches!(decl.output, FnRetTy::DefaultReturn(_)))
228-
|| span.ctxt() != body.value.span.ctxt()
228+
|| !span.eq_ctxt(body.value.span)
229229
|| in_external_macro(cx.sess(), span)
230230
{
231231
return;

clippy_lints/src/methods/option_map_unwrap_or.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(super) fn check<'tcx>(
6767
}
6868
}
6969

70-
if unwrap_arg.span.ctxt() != map_span.ctxt() {
70+
if !unwrap_arg.span.eq_ctxt(map_span) {
7171
return;
7272
}
7373

0 commit comments

Comments
 (0)