Skip to content

Commit

Permalink
Auto merge of rust-lang#119531 - petrochenkov:cmpctxt, r=cjgillot
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
bors committed Jan 6, 2024
2 parents 84c4b52 + e10a05d commit d1b8d9c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/unnecessary_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub(super) fn check<'tcx>(
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
if let Some(id) = path_to_local(cast_expr)
&& let Some(span) = cx.tcx.hir().opt_span(id)
&& span.ctxt() != cast_expr.span.ctxt()
&& !span.eq_ctxt(cast_expr.span)
{
// Binding context is different than the identifiers context.
// Weird macro wizardry could be involved here.
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/implicit_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
vis.visit_ty(impl_.self_ty);

for target in &vis.found {
if item.span.ctxt() != target.span().ctxt() {
if !item.span.eq_ctxt(target.span()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/implicit_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
_: LocalDefId,
) {
if (!matches!(kind, FnKind::Closure) && matches!(decl.output, FnRetTy::DefaultReturn(_)))
|| span.ctxt() != body.value.span.ctxt()
|| !span.eq_ctxt(body.value.span)
|| in_external_macro(cx.sess(), span)
{
return;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/option_map_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(super) fn check<'tcx>(
}
}

if unwrap_arg.span.ctxt() != map_span.ctxt() {
if !unwrap_arg.span.eq_ctxt(map_span) {
return;
}

Expand Down

0 comments on commit d1b8d9c

Please sign in to comment.