Skip to content

Commit 52c9906

Browse files
Use Span::eq_ctxt method instead of .ctxt() == .ctxt()
1 parent 2c3bb42 commit 52c9906

File tree

7 files changed

+12
-9
lines changed

7 files changed

+12
-9
lines changed

compiler/rustc_middle/src/mir/spanview.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ fn trim_span_hi(span: Span, to_pos: BytePos) -> Span {
667667
fn fn_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span {
668668
let fn_decl_span = tcx.def_span(def_id);
669669
if let Some(body_span) = hir_body(tcx, def_id).map(|hir_body| hir_body.value.span) {
670-
if fn_decl_span.ctxt() == body_span.ctxt() { fn_decl_span.to(body_span) } else { body_span }
670+
if fn_decl_span.eq_ctxt(body_span) { fn_decl_span.to(body_span) } else { body_span }
671671
} else {
672672
fn_decl_span
673673
}

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ fn non_exhaustive_match<'p, 'tcx>(
803803
let mut suggestion = None;
804804
let sm = cx.tcx.sess.source_map();
805805
match arms {
806-
[] if sp.ctxt() == expr_span.ctxt() => {
806+
[] if sp.eq_ctxt(expr_span) => {
807807
// Get the span for the empty match body `{}`.
808808
let (indentation, more) = if let Some(snippet) = sm.indentation_before(sp) {
809809
(format!("\n{}", snippet), " ")
@@ -830,7 +830,7 @@ fn non_exhaustive_match<'p, 'tcx>(
830830
" ".to_string()
831831
};
832832
let comma = if matches!(only.body.kind, hir::ExprKind::Block(..))
833-
&& only.span.ctxt() == only.body.span.ctxt()
833+
&& only.span.eq_ctxt(only.body.span)
834834
{
835835
""
836836
} else {
@@ -841,10 +841,10 @@ fn non_exhaustive_match<'p, 'tcx>(
841841
format!("{}{}{} => todo!()", comma, pre_indentation, pattern),
842842
));
843843
}
844-
[.., prev, last] if prev.span.ctxt() == last.span.ctxt() => {
844+
[.., prev, last] if prev.span.eq_ctxt(last.span) => {
845845
if let Ok(snippet) = sm.span_to_snippet(prev.span.between(last.span)) {
846846
let comma = if matches!(last.body.kind, hir::ExprKind::Block(..))
847-
&& last.span.ctxt() == last.body.span.ctxt()
847+
&& last.span.eq_ctxt(last.body.span)
848848
{
849849
""
850850
} else {

compiler/rustc_mir_transform/src/coverage/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
121121

122122
let source_file = source_map.lookup_source_file(body_span.lo());
123123
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
124-
fn_sig.span.ctxt() == body_span.ctxt()
124+
fn_sig.span.eq_ctxt(body_span)
125125
&& Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.lo()))
126126
}) {
127127
Some(fn_sig) => fn_sig.span.with_hi(body_span.lo()),

compiler/rustc_mir_transform/src/coverage/spans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl CoverageSpan {
195195
.expn_span
196196
.parent_callsite()
197197
.unwrap_or_else(|| bug!("macro must have a parent"))
198-
.ctxt() == body_span.ctxt()
198+
.eq_ctxt(body_span)
199199
{
200200
return Some(current_macro);
201201
}

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
18751875
let names = rib
18761876
.bindings
18771877
.iter()
1878-
.filter(|(id, _)| id.span.ctxt() == label.span.ctxt())
1878+
.filter(|(id, _)| id.span.eq_ctxt(label.span))
18791879
.map(|(id, _)| id.name)
18801880
.collect::<Vec<Symbol>>();
18811881

compiler/rustc_span/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ impl Span {
537537
pub fn ctxt(self) -> SyntaxContext {
538538
self.data_untracked().ctxt
539539
}
540+
pub fn eq_ctxt(self, other: Span) -> bool {
541+
self.data_untracked().ctxt == other.data_untracked().ctxt
542+
}
540543
#[inline]
541544
pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span {
542545
self.data_untracked().with_ctxt(ctxt)

compiler/rustc_span/src/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ impl Ident {
16411641

16421642
impl PartialEq for Ident {
16431643
fn eq(&self, rhs: &Self) -> bool {
1644-
self.name == rhs.name && self.span.ctxt() == rhs.span.ctxt()
1644+
self.name == rhs.name && self.span.eq_ctxt(rhs.span)
16451645
}
16461646
}
16471647

0 commit comments

Comments
 (0)