rustc_span: Optimize syntax context comparisons

Including comparisons with root context
This commit is contained in:
Vadim Petrochenkov 2024-01-02 23:32:40 +03:00
parent d2012259ca
commit e10a05dff3
4 changed files with 4 additions and 4 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}