Skip to content

Commit

Permalink
Add SyntaxContext::hygienic_eq.
Browse files Browse the repository at this point in the history
This combines multiple `HygieneData::with` calls into one, by combining
parts of `hygienic_eq` and `adjust_ident`.
  • Loading branch information
nnethercote committed Jun 4, 2019
1 parent f9209fc commit 6596743
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc/ty/mod.rs
Expand Up @@ -3089,7 +3089,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// comparison fails frequently, and we want to avoid the expensive
// `modern()` calls required for the span comparison whenever possible.
use_name.name == def_name.name &&
self.adjust_ident(use_name, def_parent_def_id).span.ctxt() == def_name.modern().span.ctxt()
use_name.span.ctxt().hygienic_eq(def_name.span.ctxt(),
self.expansion_that_defined(def_parent_def_id))
}

fn expansion_that_defined(self, scope: DefId) -> Mark {
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax_pos/hygiene.rs
Expand Up @@ -543,6 +543,14 @@ impl SyntaxContext {
})
}

pub fn hygienic_eq(self, other: SyntaxContext, mark: Mark) -> bool {
HygieneData::with(|data| {
let mut self_modern = data.modern(self);
data.adjust(&mut self_modern, mark);
self_modern == data.modern(other)
})
}

#[inline]
pub fn modern(self) -> SyntaxContext {
HygieneData::with(|data| data.modern(self))
Expand Down

0 comments on commit 6596743

Please sign in to comment.